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

How to make a RemoteEvent for increasing player cash?

I want to give a player some cash, but if I do it in localscript saving doesn't work, because Changed events don't work when localscript performs it.

I need a remote event for increasing player cash through Script. Fire should look like: game.ReplicatedStorage.AddCash:FireServer(5) so I want to increase localplayer's cash by 5.

Please send me, how to make it in server script.

1 comment

0

It doesn't need to be in a serverscript with leaderstats it can be in a separate script within workspace. (I also answered your question!)

3 answers

✓ Accepted answer

Well, I do agree with other options but I think you can use it much better. As I know there is many tutorials and I watches some and it shows how to do it. Well, you can type on youtube your fraze + how to do it or just on dev forums. Also try to do it on other script (change local to script normal one). Hope I helped.

  1. Put a remote in replicated storage.
  2. Put a script in workspace and make it say.
local remote = game.ReplicatedStorage.Remote
remote:OnServerEvent:Connect(function(player)
	player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 5
end)
  1. Make sure the remote is fired by something by saying remote:FireServer in a different script.

(Tell me if this helped! Accept it if it's the answer you needed!)

1 comment

0

It is what I needed, but it's not just that simple. I already have this script and it isn't working! It isn't doing anything. I have exact copy and made sure there are no errors. Also, I can't just add 5 in OnServerEvent because, in real script I use variables.

To add the player's cash, setup the server side of the RemoteEvent as such:

--Player service and the remote.
local PlayerService = game.GetService("Players")
local AddCash = game:GetService("ReplicatedStorage").AddCash


--Listen for events from the client. The player argument is there by default.
AddCash.OnServerEvent:Connect(function (player, addedcash)
	--Location of the cash.
	local cash = PlayerService.player.Cash
	cash.Value = cash.Value + addedcash
end)

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