Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make a RemoteEvent for increasing player cash?

Asked by
NorteX_tv 101
6 years ago

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.

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!) iiDev_Hunt3r 64 — 6y

3 answers

Log in to vote
1
Answered by
kapipi12 133
6 years ago

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.

Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago
  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!)

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. NorteX_tv 101 — 6y
Log in to vote
1
Answered by
Rheines 661 Moderation Voter
6 years ago

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)

Answer this question