Hello! I’ve been searching through documentation and forums but I haven’t been able to find a reliable solution.
I want to have a part that when jumped on a certain amount of times will fire a function. My problem is that I can’t figure out how to make a working debounce, and it fires multiple times when the player jumps.
I’ve tried multiple versions of the same script, this one seems to be the basic skeleton most people suggest. Does anyone have a fix or any suggestions? Thank you!
local cracks = workspace.FrozenLake:WaitForChild("Cracks")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
cracks.Touched:Connect(function(hit)
if humanoid:GetState() == Enum.HumanoidStateType.Landed then
print("JUMP")
end
end)
You can use debounce to reduce the events signals spam.
for an example you have a debounce set to false. When player lands on the part, you can set the debounce to true. Then it will no longer be able to fire multiple functions or print.
local cracks = workspace.FrozenLake:WaitForChild("Cracks")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local debounce = true
cracks.Touched:Connect(function(hit)
if humanoid:GetState() == Enum.HumanoidStateType.Landed and debounce then
debounce = false
print("JUMP")
task.wait(2)
debounce = true
end
end)
that is because a lot of the player character parts like Head/RightArm/LeftArm/Torso/HumanoidRootPart/etc… trigger the touch event a simple fix for that is to check if the hit.Name == “HumanoidRootPart”
local cracks = workspace.SpawnLocation
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
cracks.Touched:Connect(function(hit)
if hit.Name == "HumanoidRootPart" and humanoid:GetState() == Enum.HumanoidStateType.Landed then
print("Jumped")
end
end)