How can I turn this into a server script?

Hello, I was wondering if any of you guys could help me turn this into a server script?
thanks for helping!

	local Players = game.Players
	local PlayerToKick = Players.LocalPlayer.PlayerGui.AdminPannel.AdminPannelFrame.PlayerToKick.Text
	local KickPlayer = Players:FindFirstChild(PlayerToKick)
	local Reason = Players.LocalPlayer.PlayerGui.AdminPannel.AdminPannelFrame.Reason.Text
	KickPlayer:Kick(Reason)
end)

This is pretty simple. Simply use Events so you can send information from the client to the server.

2 Likes

Yes thanks for solving this but, I was wondering where and when to fire the events?

Let me type up an example for you real quick.

local Players = game.Players
local PlayerToKick = Players.LocalPlayer.PlayerGui.AdminPannel.AdminPannelFrame.PlayerToKick.Text
local KickPlayer = Players:FindFirstChild(PlayerToKick)
local Reason = Players.LocalPlayer.PlayerGui.AdminPannel.AdminPannelFrame.Reason.Text
local ServerEvent = game:GetService("ReplicatedStorage"):FindFirstChild("ServerEvent") -- or whatever the ServerEvent is named

ServerEvent:FireServer(KickPlayer, Reason)

Server script:

local ServerEvent = game:GetService("ReplicatedStorage"):FindFirstChild("ServerEvent") 

ServerEvent.OnServerEvent:Connect(function(player, KickPlayer, Reason)
KickPlayer:Kick(Reason)
end)
1 Like

Wow, tysm I have tried to come up with a solution to only being able to kick yourself for so long, thanks so much for helping!

1 Like

@Afraid4Life’s script is perfect but is just missing one thing. When you get information from a RemoteEvent you should have some way to check that the player firing the RemoteEvent should be able to be kicking players.

To do this you should add a table of admins UserIds to your server script and make sure the player firing the remote event to the server is on that list. Leaving this part out makes it possible for expoiters to kick anyone who they would like.

2 Likes

Yes that is very important, we don’t want random players kicking admins, lol.

1 Like

Yes, and always make these checks on the server side. Otherwise it would negate everything you did on the client.

1 Like

Yes that is very important also.

1 Like