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

Why isnt this damage script damaging the player?

i have been trying to make this script work for quite some time now and cant seem to get it to work. the script is supposed to damage the player who touched the brick and have a cool down so it doesent do 10 damage like every second and is a instant kill.

script.Parent.Touched:Connect(function(hit)
	local human = hit:findFirstChild ("Humanoid")
		if script.Parent.AttackCool.Value == true then
				script.Parent.AttackCool.Value = false
				human.Health = human.Health - 10
				wait(.1)
				script.Parent.AttackCool.Value = true
				print ("dmg taken")
		else
			wait()
		
	end
end)

AttackCool is a bool value in the part btw

1 answer

✓ Accepted answer

I personally like to store my bools inside the script;

--Make sure it's a normal script...
local brick = script.Parent
local canDMG = brick:WaitForChild("AttackCool") --Waits until the boolvalue loads in

brick.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum and canDMG.Value then --No need to add the == true
		canDMG.Value = false
		hum:TakeDamage(10) --Deals 10 damage to the target humanoid
		print("Damage taken!")
		wait(0.1)
		canDMG.Value = true
	end
end)

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