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)

1 comment
If I helped you out please accept my answer. Otherwise comment how I can help you better.