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

What have I done wrong? (Leaderstats not displaying, nor are folders being created as intended)

Asked by 5 years ago
Edited 5 years ago

Leaderstats will not display nor will the folder get created as intended. What have I don't wrong?

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("ExperienceSaveSystem")
local ds2 = DataStore:GetDataStore("WealthSaveSystem")
local ds3 = DataStore:GetDataStore("LevelSaveSystem")

game.Players.PlayerAdded:connect(function(Player)
    player:WaitForChild("leaderstats")? 
    local leader = Instance.new("Folder",Player)
    leader.Name = "leaderstats"
    local Experience = Instance.new("IntValue",Player)
    Experience.Name = "Experience"
    local Wealth = Instance.new("IntValue",Player)
    Wealth.Name = "Wealth"
    local Level = Instance.new("IntValue",Player)
    Level.Name = "Level"
    Level.Value = 1

        Experience.Value = ds1:GetAsync(Player.UserId) or 0
    ds1:SetAsync(Player.UserId, Experience.Value)
    Experience.Changed:connect(function()
        ds1:SetAsync(Player.UserId, Experience.Value);

        Wealth.Value = ds2:GetAsync(Player.UserId) or 0
    ds2:SetAsync(Player.UserId, Wealth.Value)
    Wealth.Changed:connect(function()
        ds2:SetAsync(Player.UserId, Wealth.Value);

        Level.Value = ds3:GetAsync(Player.UserId) or 0
    ds3:SetAsync(Player.UserId, Level.Value)
    Level.Changed:connect(function()
        ds3:SetAsync(Player.UserId, Level.Value);
    end)
end)


game.Players.PlayerRemoving:connect(function(Player)
    ds1:SetAsync(Player.UserId, Player.leaderstats.Experience.Value)
    ds2:SetAsync(Player.UserId, Player.leaderstats.Wealth.Value)
    ds3:SetAsync(Player.UserId, Player.leaderstats.Level.Value)
end)

0
It displays without any red nor blue lines in the coding page, and gives no errors, etc. Why on earth does this script fail to function as intended? frostingclowns 0 — 5y
1
remove line 7 and you do not need individual data stores just store a table. connect is deprecated, it is Connect. The parent argument to Instance.new is also deprecated. User#19524 175 — 5y
0
Aside from the table, I succeeded at repairing the flaws in my code. Although, how exactly am I supposed to compile my multiple leaderstats into a datastore table? I have never done this before. frostingclowns 0 — 5y
0
I have never seen question marks in code ._. greatneil80 2647 — 5y

Answer this question