What I am doing is making a remote and it has Up,Down,Left, and Right. What I am trying to do is click it. It worked when I just did it with the up key, but when trying adding the others in, it didn't even work. It didn't move to the position for 0.05 seconds and back up. Hope you understand what I am trying to do here and asking here. Thank you!
up = script.Parent.Up down = script.Parent.Down left = script.Parent.Left right = script.Parent.Right upOn = false downOn = false leftOn = false rightOn = false function onClicked() if not upOn then upOn = true up.CFrame = up.CFrame+Vector3.new(0,-0.09,0) wait(0.05) up.CFrame = up.CFrame+Vector3.new(0,0.09,0) upOn = false end else if not downOn then downOn = true down.CFrame = down.CFrame+Vector3.new(0,-0.09,0) wait(0.05) down.CFrame = down.CFrame+Vector3.new(0,0.09,0) downOn = false end else if not leftOn then leftOn = true left.CFrame = left.CFrame+Vector3.new(0,-0.09,0) wait(0.05) left.CFrame = left.CFrame+Vector3.new(0,0.09,0) leftOn = false end else if not rightOn then rightOn = true right.CFrame = right.CFrame+Vector3.new(0,-0.09,0) wait(0.05) right.CFrame = right.CFrame+Vector3.new(0,0.09,0) rightOn = false end script.Parent.ClickDetector.MouseClick:connect(onClicked)
You also should not be using deprecated events. Switch from connect()
to Connect()
.
You should also be using local
on most of your codes.
A fix to your code.
-- [Declaration Section] local Up = script.Parent.Up; local Down = script.Parent.Down; local Left = script.Parent.Left; local Right = script.Parent.Right; --\\ Variables local UpOn = false; local DownOn = false; local LeftOn = false; local RightOn = false; -- [Processing Section] local function On_Clicked () if not UpOn then UpOn = true; up.CFrame = up.CFrame + Vector3.new(0, -0.09 ,0); wait() up.CFrame = up.CFrame + Vector3.new(0, 0.09 ,0); UpOn = false; elseif not DownOn then DownOn = true; Down.CFrame = Down.CFrame + Vector3.new(0, -0.09 ,0); wait() Down.CFrame = Down.CFrame + Vector3.new(0, 0.09 ,0); DownOn = false; elseif not LeftOn then LeftOn = true; Left.CFrame = Left.CFrame + Vector3.new(0, -0.09 ,0); wait() Left.CFrame = Left.CFrame + Vector3.new(0, 0.09 ,0); LeftOn = false; elseif not RightOn then RightOn = true; Right.CFrame = Right.CFrame + Vector3.new(0, -0.09 ,0); wait() Right.CFrame = Right.CFrame + Vector3.new(0, 0.09 ,0); RightOn = false; else return; end; end; -- [Connecting Section] script.Parent.ClickDetector.MouseClick:Connect(On_Clicked);