I've tested this script in studios and it does the same thing in the actual game, It saves data and 50% of the time it doesn't. I'm relatively new to DataStore so I thought it was a good idea to ask you guys.
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderboardSaveSystem")
switch = false
switch2 = false
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Speed = Instance.new("NumberValue",leader)
local Rebirth = Instance.new("NumberValue",leader)
Speed.Name = "Speed"
Rebirth.Name = "Rebirth"
Speed.Value = ds:GetAsync(player.UserId)
Speed.Value = ds:GetAsync(player.UserId)
ds:SetAsync(player.UserId, Speed.Value)
ds:SetAsync(player.UserId, Rebirth.Value)
Speed.Changed:connect(function()
if switch == false then
switch = true
print("sanic")
ds:SetAsync(player.UserId, Speed.Value)
wait(7)
switch = false
end
end)
Rebirth.Changed:connect(function()
if switch2 == false then
switch2 = true
print("rebirth'd")
ds:SetAsync(player.UserId, Rebirth.Value)
wait(7)
switch2 = false
end
end)
end)
game.Players.PlayerRemoving:connect(function(player)
print("player left")
ds:SetAsync(player.UserId, player.leaderstats.Speed.Value)
ds:SetAsync(player.UserId, player.leaderstats.Rebirth.Value)
end)

1 comment
You're setting different values for the same key.