Hello there, im currently trying to make a game where u can press a text button on a surface gui on a part. Part -SurfaceGui -textbutton -localscript
frame = game.StarterGui.ScreenGui.Frame1
script.Parent.Parent.MouseButton1Click:connect(function()
frame.Visible = false
end) --- And when i try the game and i press the button it doesnt do anything, my goal is to make it open a frame, in this case called frame1 here is a picture of what im working on. !Image
This is because StarterGui
is a replication Service, meaning that whatever is a descendant of this Service will be promptly relocated to the PlayerGui
Service on the Client's connection to the Server. Afterwards, any affirmations made to any descendants of StarterGui
will not replicate, though will still manipulate the Instance accordingly, again.
This is primitively because this Service is meant for the Sever itself, usually to store any UI-related work for when the Player begins the Game.
The PlayerGui
is the Service that will take on the job for handling the User-Interface from there forward, so to properly display the desired outcome, you must reference the Frame as a descendant of PlayerGui
to see results.
Change game.StarterGui
to game.Players.PlayerGui
.
Additional Notes:
The MouseButton1Click
method wouldn't work on a SurfaceGui
Object, it must be GUIButton for this method to register according to the ROBLOX Developer Wiki.
Instead, write script.Parent
for the TextBox
; if this is actually restrictive to GUIButtons, then you'll have to replace the TextBox
with a TextButton
.
frame = game:GetService("Players").LocalPlayer--to access the local player script.Parent.Parent.MouseButton1Click:connect(function()--when the button is clicked it runs the function frame.PlayerGui.ScreenGui.Frame1.Visible = true--makes the frame visible end)
The StarterGui and the PlayerGui are different things. The StarterGui is where all the GUIs are held and whenever a player joins the game all the GUIs in the StarterGui are moved into the PlayerGui. This is important because if you are editing something in the StarterGui, it will not be seen by players who have already joined. You would want to modify the PlayerGui. I don't know how to get a player from a text button on a surface gui but with a click detector you can pass through the Player like this:
script.Parent.ClickDetector.MouseClick:Connect(function(plr) plr.PlayerGui.NameOfGui.Frame.Visible = true end)
Worst case you could just put a part in front of the button that is invisible and put a click detector in it.