Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.