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

Why would this fail?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
01--Closes Gui
02function onChatted(message, player)
03    if message == "/Close"  then
04     game.StarterGui.StatusGui.Status.Visible = false
05    else
06        game.StarterGui.StatusGui.Status.Visible = true
07    end
08end
09 
10game.Players.PlayerAdded:connect(function(player)
11    player.Chatted:connect(function(message) onChatted(message, player) end)
12end)

I might have made an error somewhere but cant seem to find it. I used a similar script to kill the character but this one seems to not work. Is it not possible to use this method to close a Gui? What other options could be used?

0
Uh-oh, StarterGui alert. User#6546 35 — 9y
0
Thank you for the answer, this will really help my future scripting and let me carry on working on my game. ZikesYT 0 — 9y

2 answers

Log in to vote
2
Answered by 9 years ago

You're using StarterGui
And so did everyone else, once upon a time

When you're changing something in StarterGui, the Player won't notice until they respawn. What you need to do instead is change it in the Player.PlayerGui

1function onChatted(message, player)
2    if message == "/Close"  then
3        player.PlayerGui.StatusGui.Status.Visible = false
4    else
5        player.PlayerGui.StatusGui.Status.Visible = true
6    end
7end

As a side note, your else block probably won't work how you want it to, because that will make it reappear if the Player says anything else.

Ad
Log in to vote
0
Answered by 9 years ago

You're changing the Gui of a Player, not the StarterGui because that would show up for everyone(it would not work anyway).

PlayerGui instead of StarterGui

Answer this question