Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you pass multiple arguments through a remote event?

Asked by 8 years ago

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

01local toggle = false
02function Run(input)
03    if input.KeyCode == Enum.KeyCode.LeftShift then
04        workspace.Folder.RemoteEvent:FireServer(game.Players.LocalPlayer:GetFullName(),toggle)
05        if toggle then
06            toggle = false
07        else
08            toggle = true
09        end
10        print(toggle)
11    end
12end
13game:GetService("UserInputService").InputBegan:connect(Run)

Global script:

1function run(char,toggle)
2    if toggle then
3        char.Character.Humanoid.WalkSpeed = 100
4    else
5        char.Character.Humanoid.WalkSpeed = 16
6    end
7end
8script.Parent.RemoteEvent.OnServerEvent:connect(run)
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 User#5423 17 — 8y

1 answer

Log in to vote
4
Answered by 8 years ago

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:

01local toggle = false
02function Run(input)
03    if input.KeyCode == Enum.KeyCode.LeftShift then
04        workspace.Folder.RemoteEvent:FireServer(toggle) -- This was the only problem. The first parameter is always the player.
05        if toggle then
06            toggle = false
07        else
08            toggle = true
09        end
10        print(toggle)
11    end
12end
13game:GetService("UserInputService").InputBegan:connect(Run)

Server:

1function run(char,toggle)
2    if toggle then
3        char.Character.Humanoid.WalkSpeed = 100
4    else
5        char.Character.Humanoid.WalkSpeed = 16
6    end
7end
8script.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.

Ad

Answer this question