Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this script that is supposed to deal damage not working?

Asked by 9 years ago

The script is a script in a weapon that is supposed to deal damage to a player. It's not working, and I don't know why. Output didn't give me anything. Can someone please help me?

Here's the script:

on=true
function onhit(hit)
if not on then return end
on=false
local Dmg=105
local humanoid = hit.Parent:findFirstChild("Humanoid")
local player = game.Players:findFirstChild(hit.Parent.Name) 
if humanoid ~= nil then
if player and player.TeamColor ~= script.Parent.creator.Value.TeamColor then 
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - Dmg
script.Parent.Anchored=true
script.Parent.CanCollide=false
script.Parent.Anchored=true
script.Parent.CanCollide=false
script.Parent.Throw.Looped=false
script.Parent.Throw.Volume=0

wait(2)

script.Parent:Destroy()
end
end

script.Parent.Anchored=true
script.Parent.CanCollide=false
script.Parent.Throw.Looped=false
script.Parent.Throw.Volume=0
script.Parent.Throw:stop()

wait(2)

script.Parent:Destroy()
end
script.Parent.Touched:connect(onhit)

1 answer

Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

Try keeping CanCollide to true. Maybe the Touched event doesn't fire when CanCollide is false?

Ad

Answer this question