Kick Script Not Working

Hello, I am trying to make made an admin panel GUI that I can use in my games, and I can’t seem to get it working right. To see what player it needs to kick, it needs to look at what the player puts in a text box. This means that it needs to be a local script. But, if it’s a local script then it only would happen for the player trying to kick someone. I have tried changing it to a server script, which didn’t work. The only other thing I can think of that might work is it telling another script what the text the player put in the text box, and then running a server script that would kick them. But, I don’t know how to do this. I am new to scripting and I am still learning, so I’m sorry if the solution is very obvious.

Here is the script, which is local in a button, that I have tried.

Script

local TextBox = script.Parent.Parent.TextBox

script.parent.MouseButton1Click:Connect(function()

if game.Players[TextBox.Text] then

game.Players[TextBox.Text]:Kick()

end

end)

GUI (If needed)

Thank you!

You can only kick people who isn’t yourself on the server- make a remote event for this and kick players on the server side

1 Like

Remote Events are your friend!
The linked wiki article has some excellent instructions on how to use them, and I advise reading those instructions regardless. But for an example on how to use them with your intended use:

Basically, you put the “RemoteEvent” object anywhere you want.
On the client localscript script, perform something along the lines of RemoteEvent:FireServer(TextBox.Text) …when the button is clicked. This sends the information to the server, and any serverscript connected to this RemoteEvent will have the event fire with the given information (as well as the player who fired the event).

In a different script for the server, you kick the player from here using code something like:
RemoteEvent.OnServerEvent:Connect(function(callingPlayer, playerToKick) game.Players[playerToKick]:Kick() end)

2 Likes

An add onto this is to add security and make sure the callingPlayer is infact an admin.

3 Likes

Darn, yeah.

It’s always good to practice secure scripting measures. While normally only your scripts can call these function/events only when you want them to, exploiters in your game can ignore these limitations and call RemoteEvents and RemoteFunctions whenever and however they want.

So in order to exploiter-proof this part of your game, you’d want to check that whoever is sending the event (the callingPlayer in my example) is an admin, so you can’t have exploiters firing the event for the server to kick whoever they want.

2 Likes

Thank you! I will try this out now. Thank you for explaining it very well and going in depth.

1 Like