As the title states, I’m looking to see if there’s a way to get the arguments passed in an OnServerEvent or OnClientEvent for a RemoteEvent and print them to the output.
Eg if i do OnServerEvent(player, amount) and I run a piece of code to print them out, it’d return {player, amount} in a table, or something along the lines of that.
-- script 1
RemoteEvent.OnClientEvent(player, amount)
-- etc
end
-- script 2
print(RemoteEvent.args) -- output = {player, amount}
-- or
for i, v in pairs(RemoteEvent.args) do -- output = player amount
print(v)
end
I can see what your trying to accomplish.
Try this:
local remote = game.ReplicatedStorage.RemoteEvent
remote.OnServerEvent:Connect(function(player, amount)
local args = {
player,
amount,
}
for i, v in pairs(args) do
print(i, v)
end
end)
for i,v in pairs(game:GetDescendants()) do
if v:IsA("RemoteEvent") then
v:OnServerEvent:Connect(function(...)
local args = {...}
for i,v in ipairs(args) do
print(i,v)
end
end
end)
end
You’re attempting to do a global connection to all remote events. You can try using a collection tag. However, my solution was an example for directly connecting to a remote event, and printing the arguments passed.
local remote = game.ReplicatedStorage.RemoteEvent
remote.OnServerEvent:Connect(function(player, amount)
local args = {
player,
amount,
}
for i, v in pairs(args) do
print(i, v)
end
end)
for an on client event you don’t need to use a function for the player, you can just use the localplayer inside the script. Like this:
local remote = game.ReplicatedStorage.RemoteEvent
local player = game.Players.LocalPlayer
remote.OnClientEvent:Connect(function(amount)
local args = {
player,
amount,
}
for i, v in pairs(args) do
print(i, v)
end
end)
This is because when using a server script. You need to call the player inside the function. But I a local script the player is already used.