I've tried DataStore for awhile now and I'm sill not getting the hang of it, as in it isn't working properly, sometimes it loads the players data and sometimes it doesn't. I was hoping one of y'all could help me. Also I don't know what the rules are for reposting a questions that hasn't been answered in awhile so if that is prohibited, then my bad and I wont continue doing so.
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)
The print functions are just for testing purposes, as they do still print when the function is called, it just doesn't save the data/ update it.

1 comment
connect is deprecated, use Connect. Parent argument to Instance.new is also deprecated, and you are using data stores wrong.