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

My damage script isn't working (part goes above player's head for some reason)?

when I run this the part goes above the player's head for some reason and doesn't work

canDmg = true
damage = 45
script.Parent.Touched:connect(function(Target)
	print(1)
	if canDmg == true then
		if script.Parent.plr.Value ~= Target.Parent.Name then
			if Target.Parent:findFirstChild("Humanoid") then
				canDmg = false
				Target.Parent.Humanoid.Health = Target.Parent.Humanoid.Health - damage
				print(2)
			end
		end
	end
end)

1 answer

local canDmg = true
local damage = 45
script.Parent.Touched:connect(function(Target)
    print('Touched!')
    if canDmg == true and Target.Parent:FindFirstChild("Humanoid") and script.Parent.plr.Value ~= Target.Parent.Name  then
		print('Passed test!')
                canDmg = false
                Target.Parent.Humanoid:TakeDamage(damage)
		print('Took damage')
		wait(3)
		canDmg = true
        end
end)

Changed findFirstChild to FindFirstChild. Move around lines of codes for more organization. Added local to your variable.

Whenever you are posting a question, you need to post the Error that you receive in the console, the script, and the explanation of what you did, what the script does, and where it's located in the parental system.

I hope I fixed this, If I didn't then please comment the error! If this is fixed, then please accept my answer!

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