Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you pass multiple arguments through a remote event?

I am trying to make a run script for a game but it only turns on. When I printed the toggle from the script, it said it was the player that I passed through the remote event.

Local script

local toggle = false
function Run(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		workspace.Folder.RemoteEvent:FireServer(game.Players.LocalPlayer:GetFullName(),toggle)
		if toggle then
			toggle = false
		else
			toggle = true
		end
		print(toggle)
	end
end
game:GetService("UserInputService").InputBegan:connect(Run)

Global script:

function run(char,toggle)
	if toggle then
		char.Character.Humanoid.WalkSpeed = 100
	else
		char.Character.Humanoid.WalkSpeed = 16
	end
end
script.Parent.RemoteEvent.OnServerEvent:connect(run)

1 comment

1

The first parameter for the OnServerEvent is the player object followed by the parameters passed so, toggle would be the string passed back by the function GetFullName(). simply add another paramater to function

1 answer

✓ Accepted answer

If you go to the wiki page on the tutorial for RemoteFunctions and RemoteEvents you can see that it says the first parameter is going to be the player.

Local:

local toggle = false
function Run(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        workspace.Folder.RemoteEvent:FireServer(toggle) -- This was the only problem. The first parameter is always the player.
        if toggle then
            toggle = false
        else
            toggle = true
        end
        print(toggle)
    end
end
game:GetService("UserInputService").InputBegan:connect(Run)

Server:

function run(char,toggle)
    if toggle then
        char.Character.Humanoid.WalkSpeed = 100
    else
        char.Character.Humanoid.WalkSpeed = 16
    end
end
script.Parent.RemoteEvent.OnServerEvent:connect(run)

I hope this helped! If it did please accept this as the answer. If you're still confused, please feel free to message and ask for more help.

This discussion is preserved as it was. New answers, comments, and votes are closed.