Attempt to index nil of the team when trying to print a message

Hi there, this may seem very easy to fix however I couldn’t wrap my head around this simple thing. I’m testing to see if I can print this message for the members of the team I provided in the script however it’s not printing and I get a “attempt to index nil with ‘Team’” on line 3.

local player = game.Players.LocalPlayer

if player.Team == ("Members") then

print ("hi")


Is it in a server script? You cant get local player on server.

yes, serverscript it is, i was a bit unsure on why i was defining the localplayer too

You may try doing something like this:

local Players = game:GetService('Players')

local function PlayerAdded(Player)
   local Connection
   Connection = Player:GetPropertyChangedSignal('Team'):Connect(function()


It will work on server, and will print the team only when it will change.

would this work if i put a script inside that, it does look a bit complicated

What script do you want to put?

try by adding Name

if player.Team.Name == "Members" then

print ("hi")



script.Parent.Humanoid.MaxHealth = 100

As i said that’s server script, so it will not work.

Oh… i got this, it’s a script in a StarterCharacterScripts? If it is i’ll rewrite script

how should i define the “player”?

actually there isnt nothing that say that if its server script it wont work Team | Roblox Creator Documentation

yeah as a serverscript in a starter characterscripts

No, i mean you cant access local player on server script

like you did earlier local player = game.Players.LocalPlayer

“localplayer”, is this correct since its locally? this is inside a serverscript btw

oh ok, but you can use game.Players.PlayerAdded for that if you want

like this

  if player.Team.Name == "Members" then

print ("hi")

local Character = script.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)

local Humanoid = Character:WaitForChild('Humanoid')

local function Main()
   Humanoid.MaxHealth = 100

As he said it’s a StarterCharacterScript, so you dont need to do it like that

1 Like