Please can someone tell me why this isn't working and how I can fix it.
A regular script in ServerScriptService
The values are given to the player but aren't saved.
local DSS = game:GetService("DataStoreService") local leveldatastore = DSS:GetDataStore("LevelNumber") game:GetService("Players").PlayerAdded:connect(function(player) local playerid = player.UserId local level = Instance.new("NumberValue",player) level.Name = "level" local levelfound = leveldatastore:GetAsync(playerid) if levelfound == true then level.Value = levelfound[1] else local leveltobesaved = {level.Value} leveldatastore:SetAsync(playerid,leveltobesaved) end end) game.Players.PlayerRemoving:connect(function(player) local playerid = player.UserId local leveltobesaved = {player:WaitForChild("level").Value} leveldatastore:SetAsync(playerid,leveltobesaved) end)
local DSS = game:GetService("DataStoreService") local leveldatastore = DSS:GetDataStore("LevelNumber") game:GetService("Players").ChildAdded:connect(function(player) wait(1) local playerid = player.UserId local level = Instance.new("NumberValue",player) level.Name = "level" local levelfound = leveldatastore:GetAsync(playerid) if levelfound == true then level.Value = levelfound[1] else local leveltobesaved = {level.Value} leveldatastore:SetAsync(playerid,leveltobesaved) end end) game.Players.PlayerRemoving:connect(function(player) local playerid = player.UserId local leveltobesaved = {player:WaitForChild("level").Value} leveldatastore:SetAsync(playerid,leveltobesaved) end)