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

Attempt to index nil with 'Team', can anyone help?

local JailSystemFolder = ReplicatedStorage:WaitForChild("JailSystem")
local GetPrison = JailSystemFolder:WaitForChild("GetPrison")
local GetPolice = JailSystemFolder:WaitForChild("GetPolice")
local GetPrisonTeamName = GetPrison:InvokeServer()
local GetPoliceTeamName = GetPolice:InvokeServer()


if tostring(GetPlayer.Team) ~= GetPrisonTeamName and tostring(GetPlayer.Team) ~= GetPoliceTeamName then 

part I am having trouble with is line 8

1 answer

✓ Accepted answer

Don't use tostring because it will error as it is a Team instance, not a number or string. Instead, get the Team's name by Team.Name.

if GetPlayer.Team.Name ~= GetPrisonTeamName and GetPlayer.Team.Name ~= GetPoliceTeamName then

If you want it to be more specific, check if the Player's Team Color is the same as the target Team Color.

local PrisonTeamColor = Color.fromRGB(255, 0, 0) -- red
local PoliceTeamColor = Color.fromRGB(0, 0, 255) -- blue

if GetPlayer.TeamColor ~= PrisonTeamColor and GetPlayer.TeamColor ~= PoliceTeamColor then

1 comment

1

in addition, GetPlayer is nil in the script from the error, so you should also say that in the answer too

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