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)
You can't access data stores with local scripts. Make it like fire a remote event on the gui to save.