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

Why is the player returning as nil?

Asked by 8 years ago
Edited 8 years ago

Server Script in Workspace:

01game.Players.PlayerAdded:connect(function(plr)
02    local value = Instance.new("StringValue")
03    value.Value = plr.Name
04    value.Parent = game.Lighting.PlayerStore
05    script.Trigger:FireAllClients(plr)
06end)
07 
08game.Players.PlayerRemoving:connect(function(plr)
09    if game.Lighting.PlayerStore:FindFirstChild(plr.Name) then
10        game.Lighting.PlayerStore[plr.Name]:Remove()
11    end
12    script.Trigger2:FireAllClients(plr)
13end)

LocalScript in StarterGui under a ScreenGui

01local localplayer = game.Players.LocalPlayer
02local currentSlot = 0
03local back = script.Parent.Back
04local players = game.Lighting.PlayerStore:GetChildren()
05 
06local function updatelist()
07    for i,v in pairs(back:GetChildren()) do
08        v.Position = UDim2.new(.02, 0, 0, (35*currentSlot))
09    end
10    back.Size = UDim2.new(.2, 0, (.048 * currentSlot), 0)
11end
12 
13game.Workspace.Script.Trigger.OnClientEvent:connect(function(plr)
14    local player = plr.Name
15 
View all 58 lines...

I am making a custom PlayerList, and for some reason, it returns player as nil (I put a note next to where it is erroring at)

Help is appreciated, thanks! :D

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

Replication

It's nil because it genuinely is nil. Because the player was removed from the game, aside from the closure of the Instance, it is no longer replicated and does not exist on the client. Solution? Connect to the events locally - It works now.

In the off chance that it doesn't work locally, send the UserId instead.

0
that doesn't work thehybrid576 294 — 8y
Ad

Answer this question