How would I create a Multi-Use remote event?

How would I create a Multi-Use remote event? For example, multiple items in a shop that can be bought, which is controlled by one remote event. Hopefully that made sense lol

When you call the RemoteEvent, you can add in an argument with the name of the item. It would probably be something like this:

Remote:FireServer(“ItemName”)

1 Like

You can incorporate a ‘type’ attribute and from the server you can see if the type attribute is for example, a Iron Bar, you can handle what needs to be done for buying an Iron Bar and so on.

1 Like

you just put the first argument to be the key, then check if the key is this one or that one (to be honest, i though remoteevents works like that in the first place)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,key)
    if key == "heal" then
        --heals
    elseif key == "damage" then
        --damages
    end
end)

it isn’t the most efficient way, but you do get the idea, right?

1 Like

If you wanted to use just 1 function for all the shop items, you would do something like this. For example, let’s say all the shop buttons are imagebuttons. If you bought an item (a tool for example) that goes to the player’s inventory, you could do something like this for example:


Local Script:

local remote = game.ReplicatedStorage.RemoteEvent
local shopgui = script.Parent

for _, v in pairs(shopgui:GetDescendants()) do
    if v:IsA("ImageButton") then
        v.MouseButton1Click:Connect(function()
            --first check if the player has enough money i suppose
            remote:FireServer(v.Name) --Fires remote event to server with the item's name
        end)
    end
end

Now in the serverscript, we will answer the remote event. Also, make sure the tools in the ServerStorage have the same name as the ImageButton (you’ll see why). Also put them in a folder named “Items”

Server Script:

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(player, item) --player is the client, item is v.Name (the name of the item)
    local getitem = game.ServerStorage.Items:FindFirstChild(item)
    local cloneitem = getitem:Clone()
    cloneitem.Parent = player.Backpack
end)
1 Like