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

How do I get a text button to move objects on a click?

So my test here is that screen Gui named "test1" starts in the starter GUI and that the screen GUI named "test2" starts in the server storage. The idea is that if you click the button it will bring up the other one. Test 1 code

function onClick()
	game.StarterGui.test1 = game.ServerStorage
	game.SeverStorage.test2 = game.StarterGui
	
end

Test 2 code

function onClick()
	game.StarterGui.test2 = game.ServerStorage
	game.SeverStorage.test1 = game.StarterGui
	
end

here is how I am nesting the screen GUI's, frames, buttons and scripts. https://i.imgur.com/JQDJZil.png

I hope you can help and thank you for your time. I looked a lot but couldn't find a solution even though I'm sure it's obvious. Thanks!

1 answer

✓ Accepted answer

First of all, you should use LocalScripts when using guis. Because of this, the scripts cannot access ServerStorage, but if you just want to make the frames invisibible/visible, you can just change the Visible property. For example, if you had a heirarchy like this:

--[[
>test (ScreenGui)
>>Frame1 (Frame)
>>>TextButton
>>Frame2 (Frame)
>>>TextButton
>>LocalScript
]]

Inside the LocalScript, you could simply do something like this:

script.Parent.Frame1.TextButton.MouseButton1Click:Connect(function()
	script.Parent.Frame2.Visible = true
	script.Parent.Frame1.Visible = false
end)
script.Parent.Frame2.TextButton.MouseButton1Click:Connect(function()
	script.Parent.Frame1.Visible = true
	script.Parent.Frame2.Visible = false
end)

When you set Visible to false, you cannot interact with that gui or any if its descendants in any way, so you dont have to worry about the player still being able to click invisible guis.

Also, if you do need to clone something into the Player's gui, you should probably use the PlayerGui instead of StarterGui. You can look into the difference here.

2 comments

0

Thank you so much! It helped me a lot! I would upvote you if I was able.

0

Accepting the answer would be much appreciated (:

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