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

I need help with datastore saving levels can someone help?

Asked by
Plieax 66
6 years ago

So i want the game to store the level value which the player is in so that when they join the level will save if they leave. I used a youtube video but get an error on the marked line. Please help.

local DS = game:GetService("DataStoreService")
local ds = DS:GetDataStore("Level")


game.Players.PlayerAdded:connect(function(plr)



plr.CharacterAdded:connect (function(charadded)
    wait"1"
        plr.PlayerGui.Gamegui.Enabled = true
        plr.leaderstats.Level.Value = ds:GetAsync(plr.UserID) or 0 -- This is the error line --
        ds:SetAsync(plr.UserID, plr.leaderstats.Level)
        plr.leaderstats.Level.Changed:connect(function()
            ds:SetAsync(plr.UserID,plr.leaderstats.Level)
        end)






end)
game.Players.PlayerRemoving:connect (function()
    ds:SetAsync(plr.UserID, plr.leaderstats.Level.Value)    
end)
end)


0
If I helped you out please accept my answer. Otherwise comment how I can help you better. User#21908 42 — 5y

1 answer

Log in to vote
0
Answered by 6 years ago

Your problem is you are using plr.UserID when the D should be lowercase. Try replacing all of your plr.UserID with plr.UserId hope this helps. Have a great day scripting

Ad

Answer this question