Creating a custom tab for developers to easily kick and ban players, but the Remote Event I'm using won't work right!

I’m a pretty young developer, being only 13. Also, I’m new to Roblox DevForums, so please bare with me if I’m doing something wrong, thanks. :smile:

I have been recently working on a custom GUI that allows developers in my group kick and ban players. While making this system, I learned about Remote Events, and how they can allow clients and the server communicate together, which is exactly what I needed to get the system I was making to work. I visited the Roblox Developer Hub and read every little bit about Remote Events, and I did this about 3 times. Despite reading it, I wasn’t able to fix my issue. And here is where that issue comes in.

After putting together the GUI, and making both the server side, and client side scripts, I tested my system. I Inputted the players name, (Player2, as I was playing in test mode) and the Reason they were goign to be kicked kicked. After clicking the ‘Enter’ button I made, instead of the player I entered being kicked, it was PLAYER1 who was kicked, and the reason for being kicked was simply ‘Instance’. Here are my scripts that I used for this system. (Sorry for the sloppy scripting, I like to get them working before making them look better, as it allows me to understand it easier at times.)

Client side script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local remoteEvent = ReplicatedStorage:WaitForChild("KickPlayer")

script.Parent.EnterButton.MouseButton1Click:Connect(function()
	remoteEvent:FireServer(game.Players:FindFirstChild(script.Parent.WhoToKick.Text), script.Parent.Reason.Text)
end)

Server side script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local remoteEvent = ReplicatedStorage:WaitForChild("KickPlayer")

local function onButtonClick(PlayerToKick, Reason)
	print(PlayerToKick) -- This was used for testing, and the value showed up as 'Player1' (???)
	print(Reason) -- This was used for testing, and the value showed up as 'Player2' (???)
	PlayerToKick:Kick(Reason)
end

remoteEvent.OnServerEvent:Connect(onButtonClick)

The solution to my issue is probably obvious. Any form of help would be appriciated. If you have any questions about my issue, feel free to ask and I will help you out. Thanks! :sunglasses:

1 Like

The first argument to OnServerEvent listeners is the player that fired the remote. Essentially you are kicking yourself if you were to fire the event.

local function onButtonClick(Player, PlayerToKick, Reason)

Do note that your script is vulnerable to exploits since you have no checks of whether or not someone is an admin so in the server script you might wanna check that the Player is actually an admin. You might also want to make sure that the admin is not kicking another admin as well.

1 Like

It’s a lot smarter to check for the player on the server, use the RemoteEvent to send the name or UserId of the player to the server, then find and kick the player on the server. The first argument of any event received by the server is whom it came from, which is why it doesn’t work. Your solution is also a disaster waiting to happen because an exploiter can fire the event and because you don’t check if they are allowed to do it and kicks straight away, any exploiter can kick anyone they like.

Thanks so much! :sunglasses: I appriciate your help! (Told ya’ it was obvious! XD)

LOL I’m aware of that! Thanks for reminding me! :wink: (Keep in mind that I’m new to developing and I’m making my way up slowly, I’ll be sure to add exploiter protection to the system soon.) No worries! :smile: