Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Save button doesn't save your data when clicking on it?

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

0

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...

0

how to get the player using sever script?

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.