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 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
--Closes Gui
function onChatted(message, player)
    if message == "/Close"  then
     game.StarterGui.StatusGui.Status.Visible = false
    else
        game.StarterGui.StatusGui.Status.Visible = true
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

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 — 8y
0
Thank you for the answer, this will really help my future scripting and let me carry on working on my game. ZikesYT 0 — 8y

2 answers

Log in to vote
2
Answered by 8 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

function onChatted(message, player)
    if message == "/Close"  then
        player.PlayerGui.StatusGui.Status.Visible = false
    else
        player.PlayerGui.StatusGui.Status.Visible = true
    end
end

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 8 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