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 3 years ago

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

local DS = game:GetService("DataStoreService")
local DS1 = DS:GetDataStore("SaveJoins")

game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Player:WaitForChild("leaderstats")
    local Joins = Instance.new("IntValue", leaderstats)
    Joins.Name = "Joins" 
    Joins.Value = DS1:GetAsync(Player.UserId)
    Joins.Value = Joins.Value + 1
end)

game.Players.PlayerAdded:Connect(function(Player)
    DS1:GetAsync(Player.UserId, Player.leaderstats.Joins.Value)
end)

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 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.)

local DS = get:GetService("DataStoreService")
local DS1 = DS:GetDataStore("SaveJoins")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder") --You need to create a folder.
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local joins = Instance.new("IntValue") --do not use the 2nd parameter of Instance.new() as it is somewhat slower, and considered deprecated.
    joins.Name = "Joins"
    joins.Parent = leaderstats
 end)

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

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

local DS = game:GetService("DataStoreService")
    local DS1 = DS:GetDataStore("SaveJoins")

    game.Players.PlayerAdded:Connect(function(Player)
        local leaderstats = Instance.new("Folder")
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = Player

        local Joins = Instance.new("IntValue", leaderstats)
        Joins.Name = "Joins"
        Joins.Value = DS1:GetAsync(Player.UserId)
        Joins.Value = Joins.Value + 1
    end)

    game.Players.PlayerAdded:Connect(function(Player)
        DS1:GetAsync(Player.UserId, Player.leaderstats.Joins.Value)
    end)

0
Why do you capitalise every word? Dovydas1118 1495 — 3y

Answer this question