Alright, so I've recently found a problem with loading my data. If I rejoin the game with another player present, it will just load his size and his cash. I'm not 100% sure if the problem occurs when saving or loading.
local service = game:GetService("DataStoreService")
local datastore = service:GetDataStore("PlayerSize4")
game.Players.PlayerAdded:Connect(function(plr)
local datatoload = {}
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local size = Instance.new("IntValue")
size.Name = "Size"
size.Parent = leaderstats
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local success,errorm = pcall(function()
datatoload = datastore:GetAsync("Size-"..plr.UserId)
end)
if success then
if datatoload ~= nil then
plr.leaderstats.Size.Value = datatoload[1]
plr.leaderstats.Cash.Value = datatoload[2]
print("Data loaded")
end
else
error("Data could not be loaded.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local datatosave = {}
datatosave[1] = player.leaderstats.Size.Value
datatosave[2] = player.leaderstats.Cash.Value
local success,errorm = pcall(function()
datastore:SetAsync("Size-"..player.UserId, datatosave)
end)
if success then
print("Data saved")
else
error("An error occured while saving")
end
end)

2 comments
what is player2 on line 4?
Just something I forgot to remove. But that's sadly not the problem.