so i want to create a shop for a simulator and when a player doesnt have enough coins instead of saying something like “not enough coins” or smthn like that how do i make it so that for example. a player has 100 coins but the tool he is gonna buy is 200 coins and when he tries to purchase it it says something like “you need 100 more coins to buy this item”
basically i want it to check how much more coins the player needs to buy an item
Remote functions almost work as RemoteEvents but there are two main differences: the function will yield the code until it gets something returned and you can send back to who invoked it something which you can’t do with remote events.
To “ask” the server how many coins a player has invoke the function on the client.
Example:
local RemoteFunction = game.ReplicatedStorage.RemoteFunction
local coins = RemoteFunction:InvokeServer()
As you can see there is a variable associated to the function call as the function will return the player’s coins. It’s important to note that if the function doesn’t return anything whatever is after the function call won’t run.
To listen to the call on the server simply do
local RemoteFunction = game.ReplicatedStorage.RemoteFunction
RemoteFunction.OnServerInvoke = function(player)
return playerCoinsValue
end)
As RemoteEvents RemoteFunctions also have the player argument as first parameter when invoked by the client
Once the value is returned you can calculate how much coins the player needs by subtracting to the total needed coins the amount the player has.