Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Leaderboard DataStore script is not working?

Here I have a script for saving leaderstats, but it doesn't work? Any help would be appreciated!

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder",plr)
	folder.Name = "leaderstats"
	local cash = Instance.new("IntValue",folder)
	cash.Name = "Cash"
	
	cash.Value = ds1:GetAsync(plr.UserId) or 0
	ds1:SetAsync(plr.UserId, cash.Value)
	
	game.Players.PlayerRemoving:Connect(function(plr)
	ds1:SetAsync(plr.UserId, cash.Value)
	end)
end)

1 answer

✓ Accepted answer
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:Connect(function(plr)
    folder = Instance.new("Folder",plr)
    folder.Name = "leaderstats"
    cash = Instance.new("IntValue",folder)
    cash.Name = "Cash"

    cash.Value = ds1:GetAsync(plr.UserId) or 0
    ds1:SetAsync(plr.UserId, cash.Value)

    
end)
game.Players.PlayerRemoving:Connect(function(plr)
    ds1:SetAsync(plr.UserId, cash.Value)
    end)

This might work IDK though... have fun!

This discussion is preserved as it was. New answers, comments, and votes are closed.