output: working x10
script.Parent.Touched:Connect(function(hit) local debounce = true if hit.Parent:FindFirstChild("Humanoid") ~= nil and debounce == true then debounce = false local Roball = workspace.Roball1 local animation = Instance.new("Animation") print('working') animation.AnimationId = "rbxassetid://507770239" local anim = Roball.Humanoid:LoadAnimation(animation) anim:Play() wait(0.3) debounce = true end end)
You set the debounce to true at the startof the function.
local debounce = true function main() if debounce == true then debounce = false wait(.3) debounce = true end end
You seem to be using the concept of debounce wrong. You are initializing the variable debounce to true inside the function by stating
local debounce = true
on line 2. This means that every time the Touch event occurs, you are going to make debounce equal true. Thus the if statement will always pass because debounce will be true every time the function occurs. To solve this problem, put the line mentioned above outside the funciton like so:
local debounce = true --(Place here) script.Parent.Touched:Connect(function(hit) --(Not here) if hit.Parent:FindFirstChild("Humanoid") ~= nil and debounce == true then debounce = false local Roball = workspace.Roball1 local animation = Instance.new("Animation") print('working') animation.AnimationId = "rbxassetid://507770239" local anim = Roball.Humanoid:LoadAnimation(animation) anim:Play() wait(0.3) debounce = true end end)
Hope that helps