I know the first part works but its the part where it saves when you click the gui that doesn't.
local DataStore = game:GetService("DataStoreService")
local DS1 = DataStore:GetDataStore("ExampleDataStore")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Bricks = Instance.new("IntValue",leader)
Bricks.Name = "bricks"
Bricks.Value = DS1:GetAsync(player.UserId) or 0
DS1:SetAsync(player.UserId, Bricks.Value)
local SaveGUI = game.StarterGui.SaveGUI.SaveGUIFrame.SaveGUIButton
game.Players.PlayerRemoving:connect(function(player)
print("Saveing Data")
DS1:SetAsync(player.UserId, player.leaderstats.Bricks.Value)
print(player.Name.."'s Data of"..player.leaderstats.Bricks.Value.." "..player.leaderstats.Bricks.Name.."has been saved!")
end)
this is what doesn't work
SaveGUI.MouseButton1Click:connect(function()
DS1:SetAsync(player.UserId, player.leaderstats.Bricks.Value)
print("Saved!")
end)
end)

4 comments
Why do you have more than one 'end)'?
The last end id for the first function line 6
the last end is*
Take the PlayerRemoving out of the PlayerAdded function. It won't fix your problem but that is retarded.