Log in to vote

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

Asked by 13 days ago
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

Log in to vote
Answered by 13 days ago

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
in addition, GetPlayer is nil in the script from the error, so you should also say that in the answer too Xapelize 2586 — 12d

Answer this question