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

Nil Error Issue; Why is the Parameter Indexed as "nil" and How to Fix it?

Asked by 4 years ago

[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.

1 answer

Log in to vote
-1
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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);
0
The thing is that the new function won't be able to take any parameters if I do this justaspamaccoun 0 — 4y
0
P.S. I am not the one who downvoted you justaspamaccoun 0 — 4y
Ad

Answer this question