Hello Developers! I’m trying to make an electrical panel, and I’m having some problems, I will now answer these questions.
What do you want to achieve? Keep it simple and clear!
I want to move an object, then if I click again it moves to the other side again…
What is the issue? Include screenshots / videos if possible!
The issue is when I click it it moves to a position I don’t want, Not correct position when I click it the first time: , Correct position when I click it the second time, but it should move to that position on the first click: , then it repeats to get to this position:
, What I'm trying to say: It should move to this position on the first click: On the second click: What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I didn’t see any topic talking about this, if I’m wrong please link me to the topic, I tried searching in the Devforum.
I already have a script, but I’m having a trouble with it, it moves to a incorrect position to get the first click and second click position, I don’t know why, I don’t have any errors on the output. I’m trying to make an electrical panel, so to do it more realistic I want to do the switch move, I hope you can help me.
local ClickDetector = script.Parent.ClickDetector
local parent = script.Parent
local debounce = false
if debounce == false then
debounce = true
parent.Orientation = parent.Orientation + Vector3.new(60, 90, 0)
elseif debounce == true then
debounce = false
parent.Orientation = parent.Orientation + Vector3.new(-90, 90, 0)
Should you be adding the Vector3 value to the .Orientation value of the part? You might want to manually set what position (Vector3) and Orientation it should be when clicked.
Also, debounce isn’t typically used in that context. Instead of signaling a state, debounce typically makes it so that a user cannot click something in rapid sucession, so they set it to true before a process is finished, then to false after (with false signalling that you can now activate whatever it is again). Perhaps you’d want to rename that variable to switch or something like that, just to clarify for others.