Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to give textbox/click detector multiple functions?

I tried to make a text box that would have multiple functions. For a example you click it once it will go to the right you click it again it will go to the left with 1 button the problem is that when i try to do it i click it it goes to the left and i click it again it stays at the left here is what i tried.

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Position = UDim2.new(0.727, 0, 0.401, 0)
end)

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Position = UDim2.new(0.019, 0, 0.397, 0)
end)

Any help is appreciated.

1 comment

0

You could have a variable that holds a state and changes it based on what the last click did. For example you could say that state = "left" and if state = "left" then move it right and assign "right" to state indicating its last move.

1 answer

✓ Accepted answer

What you could have is a bool variable for example

local bool = false

script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
	if bool == false then
		script.Parent.Parent.Frame.Position = UDim.new(0,727, 0, 0.401, 0)
		bool = true
	elseif bool == true then
		script.Parent.Parent.Frame.Position = UDim2.new(0.019, 0, 0.397, 0)
	end
end)

3 comments

0

what if i could want to do 3 more functions like i can press it once it goes right again left and if i press it once again it goes up and left and again it goes down and right sorry if i sound confusing

0

After line 8, Type in bool = false

0

Thank you, you are very helpful

This discussion is preserved as it was. New answers, comments, and votes are closed.