Untitled
unknown
plain_text
2 years ago
1.9 kB
5
Indexable
--The very basic snowball
--I take partial credit for this.. Doesnt matter anyway
local Tool = script.Parent
local Ball = Tool.Handle
local MouseLoc = Tool:WaitForChild("MouseLoc",10)
local WooshSFX = Ball:WaitForChild("Woosh",1)
local DebrisService = game:GetService("Debris")
local VelocityPower = 150
function fire(direction)
local vCharacter = Tool.Parent
local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)
snowballclone = Tool:FindFirstChild("Handle"):Clone()
local spawnPos = vCharacter.PrimaryPart.Position
spawnPos = spawnPos + (direction * 5)
snowballclone.Position = spawnPos
snowballclone.Velocity = direction * VelocityPower
snowballclone.Locked = true
snowballclone.Name = "ThrownSnowball"
snowballclone.CanCollide = true
snowballclone:FindFirstChild("Snow").Enabled = true
WooshSFX:Play()
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = vPlayer
creator_tag.Name = "creator"
creator_tag.Parent = snowballclone
snowballclone.Parent = workspace
--damage function--
snowballclone.Touched:Connect(function(hit)
local human = hit:FindFirstChild("Humanoid") or hit.Parent:FindFirstChild("Humanoid")
if human and hit.Parent.Name ~= Tool.Parent.Name then
human.Health = human.Health - 30
snowballclone:Destroy()
end
end)
DebrisService:AddItem(snowballclone,2)
end
Tool.Enabled = true
function onActivated()
if not Tool.Enabled then
return
end
Tool.Enabled = false
local character = Tool.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then
return
end
local targetPos = MouseLoc:InvokeClient(game:GetService("Players"):GetPlayerFromCharacter(character))
local lookAt = (targetPos - character.Head.Position).unit
fire(lookAt)
wait(2)
Tool.Enabled = true
end
Tool.Activated:Connect(onActivated)
Editor is loading...
Leave a Comment