script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
hit.Parent.Humanoid:TakeDamage(5)
end
end)
So, as you know, multiple body parts hit the part whenever you step on it. The problem is whenever you step on the part, multiple body parts hit the part, causing the part to deal 5 more damage every time a body part is touching it. Can you guide me in the right direction(not write out a script for me so, I can learn) to make the script only damage the player once? Thanks in advance!
You can use a debounce table where you insert the player’s name into and remove it after like 3 seconds. And you’re also going to need to check if the player’s name is inside the table everytime the car touches his character, so it doesn’t damage him more than once.
local Debounce = false
script.Parent.Touched:Connect(function(hit)
if Debounce == false then
Debounce = true
if hit.Parent:FindFirstChild("Humanoid")then
hit.Parent.Humanoid:TakeDamage(5)
end
wait(3)
Debounce = false
end)
local hits = {}
part.Touched:Connect(function(hit)
local character = hit:FindFirstAncestorWhichIsA("Model")
local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
if humanoid and humanoid.Health > 0 and not hits[character] then
hits[character] = true
humanoid:TakeDamage(10)
task.wait(3)
hits[character] = nil
end
end)
I’m more of a beginner scripter so this is all confusing. I think I want to learn debounce first to understand it better, then add the suggestions/scripts that you said giggio.
Edit: I’m in the middle of school so sorry if I sound dumb.
I have created one but you have to insert the debounce. Put it under the part that will make you take damage
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5
end)
end)
Edit: I found it and modified it from the script of the kill brick from the starter obby map in studios
Lol. I appreciate everyone helping me. I can’t really reply because I’m in school. Thanks! If I don’t get back to you that’s probably why. I’ll look at everything in my free time.
local Hits = { }
newFire.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if Hits[Hit.Parent] then
return
end
Hits[Hit.Parent] = true
Hit.Parent.Humanoid:TakeDamage(5)
wait(1)
Hits[Hit.Parent] = nil
end
end)
Do something like this. Easier. And if the objects inside the hit table’s name are the same they won’t get damage.
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid")then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5
end
end)