No errors but non functional script

My friend is trying to create a script that works like this, when you say ‘GuiTest’, a gui appears.

Though, this doesn’t work.

Code:

local basementSec = game.Workspace.SECRETBASEMENT
local GUI = script.Parent:WaitForChild("CharacterSelection")

game.Players.PlayerAdded:Connect(function(fans)
    fans.Chatted:Connect(function(msg)
        if msg == "GuiTest" then
            GUI.ImageButton.Visible = true
        end 
    end) 
end)

The code is a local script in StarterGui.

1 Like

The LocalScript is executed after the player joins the game, so the Players.PlayerAdded event will not fire for the local player. You have to use Players.LocalPlayer

local basementSec = game.Workspace.SECRETBASEMENT
local GUI = script.Parent:WaitForChild("CharacterSelection")
local player = game.Players.LocalPlayer

player.Chatted:Connect(function(msg)
	if msg == "GuiTest" then
		GUI.ImageButton.Visible = true
	end 
end)
1 Like

You don’t need to use PlayerAdded event, try this instead:

local Player = game.Players.LocalPlayer
local basementSec = game.Workspace.SECRETBASEMENT
local GUI = script.Parent:WaitForChild("CharacterSelection")

Player.Chatted:Connect(function(msg)
    if msg == "GuiTest" then
        GUI.ImageButton.Visible = true
    end 
end) 
1 Like