Hi I have some problems with my debounce, I’m trying to make a script that moves an object’s X negatively, but just when debounce is true, it stops moving, I tried anything that I know to make it last, but it doesn’t work, what do I do?
Okay, i see what you mean. maybe use tween service, and use a debounce on the button press cold down, and use a debounce to check if it is down or not. I can make a code if you need
Recommenddation Put the deactive and active button in a folder then put a script in that folder, so i can acess them easier in one script. Also remove the scripts in the buttons because you only need one
You forgot to set debounce back to false after the wait() function
Also ideally, debounce should be the first thing you change right after executing, so debounce = true should come right after the if statement, and debounce = false should be the last thing that runs
local TweenService = game:GetService("TweenService")
local ActiveButton = script.Parent.Activate.ClickDetector
local DeactiveButton = script.Parent.Deactivate.ClickDetector
local MovingPart = script.Parent.Light
local On = false
local CoolDown = false
ActiveButton.MouseClick:Connect(function()
if On == false and CoolDown == false then
On = true
CoolDown = true
MovingPart.Color = Color3.new(0.0980392, 1, 0)
local MovePart = TweenService:Create(MovingPart, TweenInfo.new(1),{CFrame = MovingPart.CFrame + Vector3.new(0,-5,0)})
MovePart:Play()
MovePart.Completed:Wait()
CoolDown = false
end
end)
DeactiveButton.MouseClick:Connect(function()
if On == true and CoolDown == false then
On = false
CoolDown = true
MovingPart.Color = Color3.new(1, 0, 0)
local MovePart = TweenService:Create(MovingPart, TweenInfo.new(1),{CFrame = MovingPart.CFrame + Vector3.new(0,5,0)})
MovePart:Play()
MovePart.Completed:Wait()
CoolDown = false
end
end)
This works but it doesn’t change color yet, sure you can do that yourself
BTW Light is the moving part, so just go in the script and change moving part to the part you are moving