I'm trying to make a save button that saves your data when you press it but it doesn't work..
Here's the code:
local DataStore = game:GetService("DataStoreService") local ds1 = DataStore:GetDataStore("MoneyDataStore") game.Players.PlayerAdded:connect(function(player) local folder = Instance.new("Folder", player) folder.Name = "PlayerData" local moneyStats = Instance.new("IntValue", folder) moneyStats.Name = "moneyAmount" moneyStats.Value = ds1:GetAsync(player.UserId) or 0 local saves = coroutine.create(function() --//Save Button local saveiconbutton = game.StarterGui.MenuGUI.SaveIconButton local moneyStats = player.PlayerData.moneyAmount saveiconbutton.MouseButton1Click:connect(function() print("you pressed the button!") ds1:SetAsync(player.UserId, moneyStats.Value) end) end) coroutine.resume(saves) --//Autosaves while wait(5) do ds1:SetAsync(player.UserId, moneyStats.Value) end end)
When I press the button it doesn't print, "you pressed the button!"? Why doesn't this work?
Simple
StarterGui
only holds the GUIs that will be replicated to the clients, not the actual GUI found on their screen. It can be found at game.Players[PlayerName].PlayerGui
. If you have FE on, this will be nil and you need to use remote events
to send a click to the server.