I have a script that when the part is touched it checks if its a player and then deals damage, but it doesnt deal damage. There are no errors.
Script:
local debounce = false
local damage = 20
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') and debounce == false then
debounce = true
hit.Parent.Humanoid:TakeDamage(damage)
wait(10)
debounce = false
end
end)
If you are damaging players / npc’s, make sure the the script is a server script and not a local script
Either that or try doing
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid") and debounce == false then
local humanoid = hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid")
debounce = true
humanoid:TakeDamage(damage)
wait(10)
debounce = false
end
end)
local domage = 20
local Interval = 10
local debounce = false
script.Parent.Touched:connect(function(hit)
if debounce == false then
debounce = true
if hit and hit.Parent and hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
end
wait(Interval)
debounce = false
end
end)
local debounce = false
local damage = 20
script.Parent.Touched:Connect(function(hit)
if not debounce then
print("LOL!")
debounce = true
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
print("FOUND HUMANOID!!!")
hum:TakeDamage(damage)
wait(10)
print("DEBOUNCE END!!")
debounce = false
end
end
end)
I had this same problem before, could you please check if the health is actually changing instead of it just being a Roblox’s GUI visual glitch?
To do this, head to the explorer when the game is running, and then enter your character’s Humanoid's properties, scroll down to “Health” and check if the value is changing when it’s supposed to.
The Script what u wrote is working for me, if its not working for you i think you did something with your Humanoid, also try this:
local debounce = false
local damage = 20
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') and debounce == false then
debounce = true
hit.Parent.Humanoid.Health -= damage
wait(10)
debounce = false
end
end)
That’s very strange, I tested your exact code in studio, and it worked for me. Maybe it’s the hit detection, or something related to a custom character in your game, if you made one.
Also, just want to point out that you don’t need to have a variable for dmg, use task.wait() instead of wait() (Its slower and less accurate), you can use and not debounce instead of and debounce == false, and that’s it.
If you’re using a custom character, this is most likely work. Otherwise, it’s because the part is hitting accesories, not body parts. Try using this code
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid") and debounce == false then
local humanoid = hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid")
debounce = true
humanoid:TakeDamage(damage)
wait(10)
debounce = false
end
end)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid") and debounce == false then
local humanoid = hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid")
humanoid:TakeDamage(damage)
debounce = true
wait(10)
debounce = false
end
end)