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?

2 comments
that is probably cause you are using player added, player added works when the player joined the game so, remove that and get the player...
how to get the player using sever script?