I need help with my script

I have a script that checks if you on the correct team then executes a code
in the output it says

ServerScriptService.Script:6: attempt to index nil with 'Team'

This is the script

local players = game:GetService("Players")
local plrr = game.Players.LocalPlayer
local LeftFoot = game.ServerStorage.Folder.LeftFoot.Middle
local LeftFoot2 = game.ServerStorage.Folder.LeftFoot.part
local function onCharacterAdded(character)
	if plrr.Team == game.Teams.test then
		local plr = game.Players:FindFirstChild(character.Name)
	local clone = LeftFoot:Clone()
		clone.Parent = character.LeftFoot
		local clone = LeftFoot2:Clone()
		clone.Parent = character.LeftFoot
	end
	
end
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

players.PlayerAdded:Connect(onPlayerAdded)

Is this in a local script? because if not then the game.Players.LocalPlayer Will not work

its a normal script in serverscriptservice

Ok so that is the issue. Local player can only be used from a local script, can you retrun the players name when they enter the game and call “OnCharacterMade” with the players name then you should be able to just do

game.Players:FindFirstChild(plrName).Team

im sorry for putting it in text format i dont know how to format it with lua

Ok so where should I put this in the script?

that will not work like that
there is no localplayer in the server side use game.Players.PlayerAdded:Connect(function(plr)
Your code
end

2 Likes

try using teamcolor as it might work?

1 Like

yes this would work exactly how you are wanting it too

1 Like

As @XmcElectricity said LocalPlayer doesn’t exist on server and will return nil so you need to remove that line

Now in here (above if statement) you should create a variable with named plrr and assign this value to plrr variable: game.Players:GePlayerFromCharacter(character)
it should look like this:

local players = game:GetService("Players")
local LeftFoot = game.ServerStorage.Folder.LeftFoot.Middle
local LeftFoot2 = game.ServerStorage.Folder.LeftFoot.part
local function onCharacterAdded(character)
    local plrr = game.Players:GetPlayerFromCharacter(character)
	if plrr.Team == game.Teams.test then
	local clone = LeftFoot:Clone()
		clone.Parent = character.LeftFoot
		local clone = LeftFoot2:Clone()
		clone.Parent = character.LeftFoot
	end
	
end
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

players.PlayerAdded:Connect(onPlayerAdded)
3 Likes

also can anyone help me with. idk how to format text with lua

Ok thank you will test it out :grinning: