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

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

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)
]]

5 comments

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

0

So? I still don't understand what i did wrong.

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.

0

Why are you connecting the same event to two functions that enable and disable visibility?

0

There are two different buttons; an on and off button.

2 answers

✓ Accepted answer

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)

5 comments

0

Why do they have to be local though?

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.

0

Thank you soooooooooooooooooooooooooooooooooo much. Appreciated

0

You're welcome.

0

They need to be LocalScripts because only they can access PlayerGui.

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.

1 comment

0

still doesn't work ;-;

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