Okay so I've made a damage script that when you touch a part you're losing 20 health.The bug isn't in the script but I want to make it so like that part damages the character only once. If I destroy the part it works but I don't intend to do it. Any suggestions?
x.Touched:connect(function(Part) if Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent:FindFirstChild("Humanoid") ~= Player.Character.Humanoid and Part.Parent.Name ~= "Wall" then Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health-20 end end)
First: Don't Do The Damage Like That, Use:
humanoid:TakeDamage(20)
Second, you should use hit:
script.Parent.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then humanoid:TakeDamage(20) end end)
Also, if you want it to make just 20 Damage, you should use script.Disabled:
script.Parent.Touched:connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then humanoid:TakeDamage(20) script.Disabled = true wait(2) script.Disabled = false end end)
There, works. Also, If you copy my script, then you have to put it in the part.
You're Welcome,
SwaggyDuckie