Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year 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
2
Answered by 1 year 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
1
in addition, GetPlayer is nil in the script from the error, so you should also say that in the answer too Xapelize 2658 — 1y
Ad

Answer this question