Working on this beginner guide on scripting: https://developer.roblox.com/en-us/onboarding/scoring-points/2
Either I am messing up this code or the guide is wrong? LOL.
The error is: ServerScriptService.Script:19: attempt to get length of a nil value
This script is supposed to create the leaderboard with a category for points, and add 1 point to each individual player every second for as long as they stay alive.
local Players = game:GetService("Players") local function onPlayerAdded(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local points = Instance.new("IntValue") points.Name = "Points" points.Value = 0 points.Parent = leaderstats end Players.PlayerAdded:Connect(onPlayerAdded) while true do wait(1) local playerList = Players:GetPlayers() for currentPlayer = 1, #playerlist do local player = playerList[currentPlayer] local points = player.leaderstats.Points points.Value = points.Value + 1 end end
You're getting a nil value because it wasn't identified properly. You have it as #playerlist
, but as stated from your local, you set it to be #playerList
(capital L). You need to change the lowercase l to a capital L. Just a simple but hard to see error. You'll need to change line 19 to this:
for currentPlayer = 1, #playerList do
We can see that you have an error that comes out in the output, the number 19 in it. This clarifies that there has been an error in line 19.
You spelled playerList
wrong... It's supposed to be #playerList
not #playerlist
while true do wait(1) local playerList = Players:GetPlayers() for currentPlayer = 1, #playerlist do local player = playerList[currentPlayer] local points = player.leaderstats.Points points.Value = points.Value + 1 end end
is wrong it has to be
while true do wait(1) local playerList = Players:GetChildren() for i, v in ipairs(playerList) do local player = v local points = player.leaderstats.Points points.Value = points.Value + 1 end end
For more look at https://developer.roblox.com/en-us/articles/Table
The article you are coding is probably old.