I was testing my game with a friend and when we joined the game for the second time, his data mixed up with mine (he had the same stats as me), I’m 99% sure that this script is the culprit. I didn’t put this in #help-and-feedback:scripting-support category because this code is a bit messy and it’s hard to find the problem
local DataStoreService = game:GetService("DataStoreService")
local datastore = DataStoreService:GetDataStore("AllData")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local ObbiesBeaten = Instance.new("IntValue")
ObbiesBeaten.Parent = leaderstats
ObbiesBeaten.Name = "Obbies Beaten"
local playerData = Instance.new("Folder")
playerData.Parent = player
playerData.Name = "playerData"
local playerDataIntContent = {"se", "e", "m", "h", "i", "nm"}
local allData
local success, err = pcall(function()
allData = datastore:GetAsync(player.UserId)
end)
if allData == nil then
allData = {
["ObbiesBeaten"] = 0;
["se"] = 0;
["e"] = 0;
["m"] = 0;
["h"] = 0;
["i"] = 0;
["nm"] = 0;
["firstjAccountAge"] = player.AccountAge
}
end
for _, value in ipairs(playerDataIntContent) do
local container = Instance.new("IntValue")
container.Parent = playerData
container.Value = allData[value]
container.Name = value
container.Changed:Connect(function(newValue)
allData[value] = newValue
end)
end
ObbiesBeaten.Value = allData["ObbiesBeaten"]
ObbiesBeaten.Changed:Connect(function(newValue)
allData["ObbiesBeaten"] = newValue
end)
Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
datastore:SetAsync(player.UserId, allData)
end)
end)
game:BindToClose(function()
local success, err = pcall(function()
datastore:SetAsync(player.UserId, allData)
end)
end)
end)