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

I need help with my datastores! They aren't loading when they join back in the game?

Asked by 6 years ago
PointData = game:GetService("DataStoreService"):GetDataStore("PointData")
RebirthData = game:GetService("DataStoreService"):GetDataStore("RebirthData")
LevelData = game:GetService("DataStoreService"):GetDataStore("LevelData")

game.Players.PlayerAdded:Connect(function(plr)
    local LB = Instance.new("IntValue",plr)
    LB.Name = "leaderstats"

    local p = Instance.new("IntValue",LB)
    p.Name = "Ornaments"
    p.Value = PointData:GetAsync(plr.userId) or 0

    local r = Instance.new("IntValue",LB)
    r.Name = "Level"
    r.Value = LevelData:GetAsync(plr.userId) or 0

    local z = Instance.new("IntValue",LB)
    z.Name = "Rebirths"
    z.Value = RebirthData:GetAsync(plr.userId) or 0

    LB.Parent = plr
    p.Parent = LB
    r.Parent = LB
    z.Parent = LB
end)

game.Players.PlayerRemoving:Connect(function(plr)
    PointData:SetAsync(plr.userId, plr.leaderstats.Points.Value)
    RebirthData:SetAsync(plr.userId, plr.leaderstats.Rebirths.Value)
    LevelData:SetAsync(plr.userId, plr.leaderstats.Level.Value)
end)

~~~~~~~~~~~~~~~~~ Please help, thanks.****

0
You never told the script to save the data... MathijsM2006 12 — 6y
0
i am not a god at scripting but defining the parents of LB, p, r and z towards the end of your code was not necessary because their parents was already defined when the variables were created in lines 6, 9, 13, and 17 hope this helps a little and helps you find answers to your code quicker, Neosavvy 2 — 6y
0
How do I tell the script to save @MathijsM2006 Masmixel 21 — 6y
0
line 28-30 is saving, SetAsync. DinozCreates 1070 — 6y
View all comments (2 more)
0
also what masmixel said, you're setting parent twice. are you testing this live or on studio? DinozCreates 1070 — 6y
0
Studio, its for a game. im making a simulator a year round one i still need a name and stuff, my only problem is when they join back the leaderstats don't load. Masmixel 21 — 6y

Answer this question