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

leaderstats not a valid member of player?

Asked by 4 years ago

Im adding a datastore and ever since I added it I got this error: leaderstats not a valid member of player

01local DS = game:GetService("DataStoreService")
02local DS1 = DS:GetDataStore("SaveJoins")
03 
04game.Players.PlayerAdded:Connect(function(Player)
05    local leaderstats = Player:WaitForChild("leaderstats")
06    local Joins = Instance.new("IntValue", leaderstats)
07    Joins.Name = "Joins"
08    Joins.Value = DS1:GetAsync(Player.UserId)
09    Joins.Value = Joins.Value + 1
10end)
11 
12game.Players.PlayerAdded:Connect(function(Player)
13    DS1:GetAsync(Player.UserId, Player.leaderstats.Joins.Value)
14end)

2 answers

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

You didn't create a leaderstats folder. Also you're using 2 PlayerAdded events. My advice is to consolidate everything into one event. (Note: I'll be putting --comments for anything critical.)

01local DS = get:GetService("DataStoreService")
02local DS1 = DS:GetDataStore("SaveJoins")
03 
04game.Players.PlayerAdded:Connect(function(player)
05    local leaderstats = Instance.new("Folder") --You need to create a folder.
06    leaderstats.Name = "leaderstats"
07    leaderstats.Parent = player
08 
09    local joins = Instance.new("IntValue") --do not use the 2nd parameter of Instance.new() as it is somewhat slower, and considered deprecated.
10    joins.Name = "Joins"
11    joins.Parent = leaderstats
12 end)

Edit: At asker's request, I sent a link to Devking's DataStoreService video. DataStoreService

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

It Doesn't Look Like You Made A leader stats folder. Unless You Made It in Another Script. If You Have Just Delay It. But If You Haven't Then Make A New Instance.

This Script Might Work IF You Haven't Made A leaderstats Folder

01local DS = game:GetService("DataStoreService")
02    local DS1 = DS:GetDataStore("SaveJoins")
03 
04    game.Players.PlayerAdded:Connect(function(Player)
05        local leaderstats = Instance.new("Folder")
06        leaderstats.Name = "leaderstats"
07        leaderstats.Parent = Player
08 
09        local Joins = Instance.new("IntValue", leaderstats)
10        Joins.Name = "Joins"
11        Joins.Value = DS1:GetAsync(Player.UserId)
12        Joins.Value = Joins.Value + 1
13    end)
14 
15    game.Players.PlayerAdded:Connect(function(Player)
16        DS1:GetAsync(Player.UserId, Player.leaderstats.Joins.Value)
17    end)
0
Why do you capitalise every word? Dovydas1118 1495 — 4y

Answer this question