So when the datastore script tries to get the Cubes value from the Datastore, it gives me an error saying "ServerScriptService.Datastore:9: Attempted to index number with number" which I have no idea on how to fix.
Datastore script:
local datastore = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrid = "id_"..plr.UserId
local save1 = plr.leaderstats.Cubes
local GetSaved = datastore:GetAsync(plrid)
if GetSaved then
save1.Value = GetSaved[0]
else
local NumSave = {save1.Value}
datastore:GetAsync(plrid,NumSave)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
datastore:SetAsync("id_"..plr.UserId,plr.leaderstats.Cubes.Value)
end)
Leaderstats script:
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cubesmade = Instance.new("IntValue")
cubesmade.Name = "Cubes"
cubesmade.Value = 0
cubesmade.Parent = leaderstats
end
Players.PlayerAdded:Connect(leaderboardSetup)

4 comments
it works now, but it won't save. Every time I rejoin the cubes get set back to 0.
Leaderstats?
?
like i dont see you setting the value