✓ Accepted answer
#Yes.
The short answer is yes, you can have one remote event to handle purchases for all items
#How do you do it?
Easy. What you can do for your event listener, is add a parameter, which I will name request. This will be what the client requests to buy.
local ServerStorage = game:GetService("ServerStorage")
local items = ServerStorage.items
local purchaseEvent = ...
local function handlePurchase(client, request)
local tool = items:FindFirstChild(tostring(request))
end
What I am doing here, is calling :FindFirstChild() just to make sure that the item they request is in the items folder, just in case an exploiter tries to send bad information, and i call tostring on request as well, because again, exploiters.
local function handlePurchase(client, request)
local tool = items:FindFirstChild(tostring(request))
if tool then
if client.Cash.Value >= tool.price.Value then
end
end
end
purchaseEvent.OnServerEvent:Connect(handlePurchase)
Finally, from a LocalScript, in some TextButton:
local purchaseEvent = ...
script.Parent.Activated:Connect(function()
purchaseEvent:FireServer(script.Parent.Name)
end)
I send the name of the button to the server, which should be the name of the tool.
######Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions, then feel free to leave them down in the comments.
2 comments
You really don't have to, One method I use is sending the command or purpose of the firing of the remote as an argument and varying what happens by checking that argument
Sorry I don't understand what you mean. Can you explain it in a bit more detail?