Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why do these scripts not activate/deactivate visibility for the gui?

Asked by 6 years ago
Edited 6 years ago
function die()
    game.StarterGui.Timer.Reset.Visible = true
    game.StarterGui.Timer.Start.Visible = true
    game.StarterGui.Timer.Stop.Visible = true
    game.StarterGui.Timer.Frame.Time.Visible = true
end

script.Parent.MouseButton1Down:connect(die)

and

function die()
    game.StarterGui.Timer.Reset.Visible = false
    game.StarterGui.Timer.Start.Visible = false
    game.StarterGui.Timer.Stop.Visible = false
    game.StarterGui.Timer.Frame.Time.Visible = false
end

script.Parent.MouseButton1Down:connect(die)

wherien when a certain button is clicked, it makes the assets visible/invisible.

--[[Note: my tree:
        game
            StarterGui
                Settings
                    Frame
                        Timer
                            Off
                                Script
                            On
                                Script
                    Open
                Timer
                    Frame
                        Time(A text label
                    Reset (txt button)
                    Stop (txt button)
                    Start (txt button)
]]
0
The GUIs that show up on your screen are part of an instance called "PlayerGui" that show up inside every player. The StarterGui is just what is replicated to each player UgOsMiLy 1074 — 6y
0
So? I still don't understand what i did wrong. RealRexTerm 21 — 6y
0
The StarterGui is what shows up to the player by default, and it is replicated to the PlayerGui. The PlayerGui is what the player actually sees. When a player joins the game or respawns, the game gets whatever is in the starter gui and copies it to their PlayerGui. In studio, you see the StarterGui, but that isn't actually what is in the game. I've made a new script below. UgOsMiLy 1074 — 6y
0
Why are you connecting the same event to two functions that enable and disable visibility? hiimgoodpack 2009 — 6y
0
There are two different buttons; an on and off button. UgOsMiLy 1074 — 6y

2 answers

Log in to vote
1
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

You would change what's in the PlayerGui, not the StarterGui

Also, make sure that all scripts inside the StarterGui/PlayerGui are Local Scripts

local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local timer = gui:WaitForChild("Timer")

script.Parent.MouseButton1Click:Connect(function()
    timer.Reset.Visible = true
    timer.Start.Visible = true
    timer.Stop.Visible = true
    timer.Frame.Time.Visible = true
end)
0
Why do they have to be local though? RealRexTerm 21 — 6y
0
As for the variables, they don't, but many people just put local before most variables. If the variable's first appearance is inside a block of code, then you should use local. UgOsMiLy 1074 — 6y
0
Thank you soooooooooooooooooooooooooooooooooo much. Appreciated RealRexTerm 21 — 6y
0
You're welcome. UgOsMiLy 1074 — 6y
0
They need to be LocalScripts because only they can access PlayerGui. ee0w 458 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

First of all, you should read this: http://wiki.roblox.com/index.php?title=PlayerGui_vs._StarterGui

I will, however, summarize it here.

Whenever your character respawns, the contents inside of StarterGui get copied to a special directory called PlayerGui, which is located inside your own Player object.

You can check it out by pressing F5 and trying to change the contents in StarterGui on the explorer while testing, and then changing the contents of PlayerGui inside your Player in the Players service.

You can access your player object by writing game.Players.LocalPlayer in a LocalScript, and your PlayerGui by either travelling the hierarchy using script.Parent.Parent.Parent (...) or by doing LocalPlayer.PlayerGui.

To fix it, you first need to make sure that both scripts are LocalScripts (their icon should be like the script's, but with a little person on them). After you do that, you can do:

timer = game.Players.LocalPlayer.PlayerGui:FindFirstChild("Timer")

function die()
    timer.Reset.Visible = false
    timer.Start.Visible = false
    timer.Stop.Visible = false
    timer.Frame.Time.Visible = false
end

script.Parent.MouseButton1Down:connect(die)

Hope this helps.

0
still doesn't work ;-; RealRexTerm 21 — 6y

Answer this question