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

Why would this fail?

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

2 comments

0

Uh-oh, StarterGui alert.

0

Thank you for the answer, this will really help my future scripting and let me carry on working on my game.

2 answers

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.

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

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