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

How can I add money to a player's balance using the server? it keeps coming up with an error

I'm currently trying to make a game that when you click a GUI button it fires the server to add $5 to the player's money count (I know I should make a leaderstats for the money but I just put it in the Gui so it's easier to reach)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	local name = player
	local valuee = game.Players.Name.PlayerGui.money
	print(name)
	valuee.value = valuee.value + 5
	
end)

it comes up with the error: ServerScriptService.Script:3: attempt to index nil with 'money'

1 answer

✓ Accepted answer

You can't get the player in that method, I also recommend putting values like this inside of the player or somewhere else like replicatedstorage

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	local value = player.PlayerGui.money
	value.Value = value.Value + 5
end)

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