I want to make a game but I need this to work inside of a gui, with a button and a localscript (it needs to be able to save with a data store)
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "Cash"
Cash.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player,leaderstats.Cash.Value)
end)

3 comments
You've got an extra end on line 14.
i meant how do i convert this inside a gui, i have 0 errors
Oh sorry, I forgot about that. I'm not sure what you're trying to do besides putting this in a GUI. Is clicking on the GUI supposed to save the player's data?