Sending multiple variables though RemoteEvent help

Hey there! I am trying to make a custom admin GUI for a game of mine. I have all the GUI made(It is very basic and it is currently just the testing version) and I have it set to where you type the player name in a designated box, select the command and then press a button that says “Execute” on it.

When the player clicks the “Execute” button this is the code that runs in a LocalScript in the button. (Sorry it isn’t colored, I can’t figure out how it’s being a bit dumb.)

 Button.MouseButton1Click:Connect(function()
    ExecuteCommand:FireServer(Button.Parent.PlayerNameBox.Text, Button.Parent.Command.Value)
    print(Button.Parent.PlayerNameBox.Text)
    print(Button.Parent.Command.Value)
 end)

And this is the code on the ServerScript.

local executeevent = game.ReplicatedStorage.ExecuteAdmin

local function ExecuteCommand(Player, Command)
     print("Execute sent")
     print(Player)
     print(Command)
     if Command == "Kick" then
	     game.Players[Player]:Kick("You have been kicked from the game.")
     end
end
endexecuteevent.OnServerEvent:Connect(ExecuteCommand)

This is what gets printed when it happens.
scripting%20help

As you can see, in the local script, it prints the right player name and command, but then when it goes to the server both of the values are the same.

I have absolutely no idea how to fix this, I’ve never ran into this issue before. Thanks so much!

2 Likes

When you fire a RemoteEvent it fires the Player who fired it with it. So the server is receiving 3 variables - The player who sent it, The player you typed in the box, and the command. To fix this add another Variable in your function in the ServerScript -

local function ExecuteCommand(PlayerWhoSent, Player, Command)

You can then use this to make sure the Player sending the command is an admin :slight_smile:

6 Likes

Thanks so much! I figured it out.