Debounce issue while making a object move

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?
image

here is what it looks like
https://i.gyazo.com/5cda8116babca97dae36f19cafebaa04.mp4

1 Like

You could have

while debounce == true do 
--move Part?
end

What you’re trying to do is very unclear to me

1 Like

It didn’t work.

What I’m trying to do is to move an object, but only once so I’m trying to use debounce, but when I use it, it stops just after I click the button.

1 Like

Wait so you want it to move once, or keep on moving while the button is hit?

Yes, only once, it has to go to the end.

look the gif, It stops moving when I click on the button

What are you trying to move? i don’t see a problem with the video

let me send you a gif without debounce, it would look like that

1 Like

https://i.gyazo.com/179a49cc1eecbd1d658af2c0bb614c36.mp4
this is without debounce
but when it is
If I click it again the object will keep moving
https://i.gyazo.com/ea780a4b718f50089770581a1a7fe7a1.mp4

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

yes please, I wouldn’t know how to make the tween service part

Okay, this is a server script right?
Also can you send a picture of the instances in the buttom model so i can script it off of the model

yes it is, It’s not with a local script

image

1 Like

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

Move the not debounce bit outside of the for loop!

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

I already tried that before, but it keeps moving!

I already put them in a folder

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)


image
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