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 4 years ago
Edited 4 years ago
1local Player = game.Players.LocalPlayer
2 
3local Points = Player.leaderstats.Points
4 
5script.Parent.Text = "Points: " .. Points.Value
6 
7Points:GetPropertyChangedSignal("Value"):Connect(function()
8    script.Parent.Text = "Points: " .. Points.Value
9end)

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 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.

01local Player = game.Players.LocalPlayer
02 
03local leaderstats = Instance.new("Folder") -- creates the new "leaderstats" folder
04leaderstats.Name = "leaderstats"
05leaderstats.Parent = Player
06 
07local Points = Instance.new("NumberValue") -- creates the new "Points" value
08Points.Name = "Points"
09Points.Parent = leaderstats
10 
11script.Parent.Text = "Points: " .. Points.Value
12 
13Points:GetPropertyChangedSignal("Value"):Connect(function()
14    script.Parent.Text = "Points: " .. Points.Value
15end)
0
you forgot to name it Harry_TheKing1 325 — 4y
0
oop GrandSnaf 77 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
01local Player = game.Players.LocalPlayer
02 
03local a,b = Instance.new("Folder"),Instance.new("NumberValue")
04a.Parent,b.Parent,a.Name,b.Name,b.Value = player,a,"leaderstats","Points",0
05 
06script.Parent.Text = "Points: "..b.Value
07 
08b:GetPropertyChangedSignal("Value"):Connect(function()
09    script.Parent.Text = "Points: "..b.Value
10end)

Answer this question