[Code]
local Players = game:GetService("Players"); local Teams = game:GetService("Teams"); local function onPlayerNew(person) local f3xClone = game.StarterPack.Gold.F3X:Clone(); f3xClone.Parent = person:WaitForChild("Backpack"); -- Trouble end local function onPlayerAdded(player) -- Check if team is Gold Builder + if spawned if player.Character and player.TeamColor == "Gold" then onPlayerNew(player); end -- Listen for the player (re)spawning player.CharacterAdded:Connect(onPlayerNew()); end -- Iterate over each player already connected -- to the game using a generic for-loop for i, player in pairs(Players:GetPlayers()) do onPlayerAdded(player); end -- Listen for newly connected players Players.PlayerAdded:Connect(onPlayerAdded);
[Error/Issue]
While running a "Playing Solo" test:
ServerScriptService.Script:6: attempt to index local 'person' (a nil value)
[Info]
I have a F3X tool in a folder in StarterPack
. I have a script in ServerScriptService
. I want only players that are part of a certain team (the TeamColor
is "Gold"
) to have this tool. I have spent a number of hours on the official documentation, but still haven't been able to find out what the issue is. Help would be greatly appreciated.
dont add "person" next time use local person = game.Players.LocalPlayer
local Players = game:GetService("Players"); local Teams = game:GetService("Teams"); local function onPlayerNew() local person = game.Players.LocalPlayer local f3xClone = game.StarterPack.Gold.F3X:Clone(); f3xClone.Parent = person:WaitForChild("Backpack"); -- Trouble end local function onPlayerAdded() -- Check if team is Gold Builder + if spawned if player.Character and player.TeamColor == "Gold" then onPlayerNew(player); end -- Listen for the player (re)spawning player.CharacterAdded:Connect(onPlayerNew()); end -- Iterate over each player already connected -- to the game using a generic for-loop for i, player in pairs(Players:GetPlayers()) do onPlayerAdded(player); end -- Listen for newly connected players Players.PlayerAdded:Connect(onPlayerAdded);