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 find things in StarterGui/out of Workspace?

Note: I'm a big noob at scripting so don't give me a complicated answer. Thanks :P

So I've made a script inside a TextButton, which, upon pressing, closes the GUI on screen. Now, that code works, but I decided to add to it by making it open a different GUI when closed. I'm pretty sure I know how to script it, but ofc, my stuff in StarterGui isn't part of Workspace. How do I find things out of Workspace? Here is my failed attempt:

script.Parent.MouseButton1Click:connect(function()
	script.Parent.Parent.Visible = false
	wait (1)
	local found = StarterGui:FindFirstChild("ChatGuiOne")
	if found then
		found.Frame.Visible = true
	end
end)

Here is roughly how my StarterGui in the Explorer looks like:

StarterGui
	ChatGuiOne
		Frame
	ChatGuiTwo
		Frame
			TextButton
				LocalScript <-- This is the script

So when ChatGuiTwo is closed, I want ChatGuiOne to open. In my script, where it says StarterGui, there is a blue line underneath.

Hopefully, that was enough detail for someone to help me XD

2 comments

0

game.StarterGui

0

This has been solved already, no need to post an answer. Big shout out to OfcPedroo for helping me out! :D

2 answers

✓ Accepted answer

TRUST ME, THIS WILL WORK

What you see when you're editing something on Roblox Studio, is the 'StarterGui', on the 'game' right? But, when you click play on the roblox studio, or even when you go play your game in roblox, the 'StarterGui' is cloned to another directory, which is game>Players>LocalPlayer>HERE

when it is inside LocalPlayer, the name is transformed to 'PlayerGui'

The StarterGui is the 'folder' that players will see globally, and you don't wanna use scripts with that.

The PlayerGui is the 'folder' that THE player will see, and that's what you wanna change.

Hope you understood what I meant there up, but anyways, I'm gonna give a clean, fresh, working copy of the script you just wrote:

script.Parent.MouseButton1Click:connect(function()

--this may seem nothing, but these 'repeat' there down are crucial for the script to work IN the game. It will work anyways in the roblox studio, but in the official game it will only work with this
    repeat wait() until game.Players.LocalPlayer.Character
    repeat wait() until game.Players.LocalPlayer:WaitForChild("PlayerGui")

    script.Parent.Parent.Visible = false
    wait (1)
    local found = script.Parent.Parent.Parent:FindFirstChild("ChatGuiOne")
    if found then
	--in here you can't use variable 'found' because that's used to FIND a child, and not CHANGE a child
        script.Parent.Parent.Parent.ChatGuiOne.Frame.Visible = true
    end
end)

In that case, I used 'Parent' so you wouldn't need to change anything, but, if you wanna refer the PlayerGui and not use script.Parent.Parent.Parent, then, first of all, REMOVE the Script. When you're referring to PlayerGui and you're not using script.Parent, then you need to use a LocalScript, so REMOVE THE SCRIPT, and ADD A LOCALSCRIPT right where the script was. Then, write THIS code:

script.Parent.MouseButton1Click:connect(function()
--this may seem nothing, but these 'repeat' there down are crucial for the script to work IN the game. It will work anyways in the roblox studio, but in the official game it will only work with this
    repeat wait() until game.Players.LocalPlayer.Character
    repeat wait() until game.Players.LocalPlayer:WaitForChild("PlayerGui")

	--Set the Object's visible bool to false
    script.Parent.Parent.Visible = false
	--wait 1 second
    wait (1)
	--make the 'found' variable and then use it to check if ChatGuiOne was found.
    local found = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ChatGuiOne")
    if found then
	--in here you can't use variable 'found' because that's used to FIND a child, and not CHANGE a child

	--switch a frame located in chatguione's visible bool to true
        game.Players.LocalPlayer.PlayerGui.ChatGuiOne.Frame.Visible = true
    end
end)

StarterGui replicates GUIs into the clients "PlayerGui" when they spawn.

Most of your active GUIs that you see on your screen are members of your PlayerGui.

Here's a modified version of your script :


script.Parent.MouseButton1Click:connect(function()
    script.Parent.Parent.Visible = false
    wait (1)
    local found = game:GetService'Players'.LocalPlayer.PlayerGui:FindFirstChild("ChatGuiOne")
    if found then
        found.Frame.Visible = true
    end
end)

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