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

Why is my team checker script that shows specific Gui's not working?

I have a local script in StarterGui that checks what teams someone is on and makes a specific Gui frame visible to them. The Gui's are enabled and everything else looked fine to me but it doesn't work.

player = game.Players.LocalPlayer
red = game.Teams:FindFirstChild('Red Team')
green = game.Teams:FindFirstChild('Green Team')
redGUI = script.Parent:FindFirstChild('RedAirfieldMap')
greenGUI = script.Parent:FindFirstChild('GreenAirfieldMap')

if player.TeamColor == red.TeamColor then
	redGUI.Frame.Visible = true
end

if player.TeamColor == green.TeamColor then
	greenGUI.Frame.Visible = true
end

1 answer

✓ Accepted answer
player = game.Players.LocalPlayer
red = game.Teams:FindFirstChild('Red Team')
green = game.Teams:FindFirstChild('Green Team')
redGUI = script.Parent:WaitForChild('RedAirfieldMap')
greenGUI = script.Parent:WaitForChild('GreenAirfieldMap')

if player.TeamColor == red.TeamColor then
    redGUI.Frame.Visible = true
end

if player.TeamColor == green.TeamColor then
    greenGUI.Frame.Visible = true
end

i take it you dont Have Output open when scripting

21:34:51.283 - Players.Player1.PlayerGui.LocalScript:12: attempt to index global 'greenGUI' (a nil value)

it means that when the script ran, The Gui did not exist yet. changing FindFirstChild to WaitForChild fixes this problem

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