Cash system not adding to intvalue in remote event

very odd. it prints the value just fine, but still doesn’t add to the value.

when changing the value (without any math) it will work fine.

This script does not print the value so I don’t know what you are talking about… did you use your old script by accident?

Got it to work:

local function addCashFired(plr, amount)
	local playerCash = plr:WaitForChild("PlayerData"):WaitForChild("Cash")
	print(playerCash.Value)
	
	local result = playerCash.Value + amount
	print(tostring(result))
	playerCash.Value = tonumber(result)

end

You can undo the frivolous casting:

local function addCashFired(plr, amount)
	local playerCash = plr:WaitForChild("PlayerData"):WaitForChild("Cash")	
	playerCash.Value += amount
end

Even though I have no clue what game/use you are doing this for, why are you using an event to give cash? That’s a very bad idea and is a potential high security risk as exploiters can abuse this. I recommend adding a check or doing it all on the server if anything.

1 Like

ok. Thanks for the advice, as a starter with remote events, I wasn’t really sure where to use them and where not to use them. I’m thinking of implementing a shop for cash and an inventory system. How would I do a check, or make this system secure (as I’ve done the same client side additions script for adding inventory items)…

I’m wondering if your problem was fixed?

yes, it was. now the issue is security of my methods.

1 Like

Ok, good :grinning: I make the same mistake all the time. Just gotta make sure you keep an eye out for that. I find it odd that it didn’t print an error message though :thinking:

1 Like

Depends on what you are doing, for example, if you just want owners to use this method, firing a remote event to earn cash, you can simply do if plr.Name == yourname then on the SERVER when it’s fired. I don’t know why you want to do this on the client, you should always manage this type of thing on the server.

If you want to do a shop system, let’s say it was a GUI, you could put a server script in the GUI, and when a player purchases an item, it will give them the item + take away the money in that same script. Nothing really has to be local here.

He split it into an event to the server from the client. Am I missing something?

what’s an example of a server script inside a gui element that would get me started on functions like this?

Actually I am mistaken. Just use a remote for purchasing, and when that remote is fired, check if the player has the amount of cash needed, then take away that cash + give the player that item.

so in the end, would it be wise to remove the client to server remote events, or keep them?

im definitely worried about security now that it’s been brought up, so I’d like to implement a similar system for buying cash, buying items (removing cash and adding to inventory) in a secure manner.

The remote is fine, but simply leaving the remote out there to generate cash is vulnerable.

What I am saying is that I suggest you put a localscript in the GUI and check if the player purchased it, then ON the server using an OnServerEvent function, check if the player has the cash required, and if he did, subtract that cash from their current balance and give them the item.

I will try to give an example. If the client sends a value of 100 to the server event, then the server will take the 100 and add it to the player’s cash. This is dangerous because there is no way to verify if the player should make 100 or 10. The client should fire the server event, but the server must be the one to set the reward.

Side note—can exploiters invoke remote functions and events from the client?

As @awesomeotheraccount suggests, let the server handle all transactions; a good thing to remember is to never trust the client, especially with intimate data such as player stats. If player input is necessary, then make sure to make as much sanity checks as possible. For example. if I wanted to make a purchasing system, I might do something like this.

local itemsForSale = {
     Item = 200;
     Item2 = 400;    
}

local purchaseEvent = your.RemoteEvent

purchaseEvent.OnServerEvent:Connect(function(plr, item) -- "item" is the Name of the stat, for example "Item"
     local cost = itemsForSale[item]
     if not cost then
       return
     end
    
     local playerCash = plr:WaitForChild("PlayerData"):WaitForChild("Cash")	
     if playerCash.Value > cost then
          playerCash.Value -= cost
          -- equip the item here; you could turn this into an OnServerInvoke event and let the client know that the purchase was a success
    end     
end)

If you can do it client sided, then they can too.

3 Likes

In short, yes they can invoke the events. This is answered right above as @AbiZinho said,

If you can do it client sided, then they can too.

So this goes to show that whatever you can do to the client as the developer, (display guis, or all gui related things, or things that are client sided) can be changed, added or removed by an exploiter. I do not have a complete understanding or awareness of what exploiters are capable of, so please look into this further.

Sorry @AbiZinho if it seems I’m trying to take credit, I am hoping to only add more clarification if at all possible to help @WindingTheRopes understand what we’re talking about.

1 Like