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

need help on what this means ServerScriptService.Script:3: attempt to index nil with 'leaderstats'?

Asked by 3 years ago
Edited 3 years ago
local Player = game.Players.LocalPlayer

local Points = Player.leaderstats.Points

script.Parent.Text = "Points: " .. Points.Value

Points:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = "Points: " .. Points.Value
end)

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Make sure that you're creating the "leaderstats" object within the player before you try to reference it, as it's not a default object / property within a Player.

local Player = game.Players.LocalPlayer

local leaderstats = Instance.new("Folder") -- creates the new "leaderstats" folder
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player

local Points = Instance.new("NumberValue") -- creates the new "Points" value
Points.Name = "Points"
Points.Parent = leaderstats

script.Parent.Text = "Points: " .. Points.Value

Points:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = "Points: " .. Points.Value
end)
0
you forgot to name it Harry_TheKing1 325 — 3y
0
oop GrandSnaf 77 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
local Player = game.Players.LocalPlayer

local a,b = Instance.new("Folder"),Instance.new("NumberValue")
a.Parent,b.Parent,a.Name,b.Name,b.Value = player,a,"leaderstats","Points",0

script.Parent.Text = "Points: "..b.Value

b:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = "Points: "..b.Value
end)

Answer this question