Admin getting kick insted of target user

Hello,

I’ve been making admin for my group and I’ve started to working on the kick player part.
The error I’m getting is when an admin “kicks” a player the admin gets kicked and the target player does not.

Video that shows the error

Code

Local Script

--Service--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserKickEvent = ReplicatedStorage.AdminEvents.UserKickEvent
--Locals--
local UserName = script.Parent.PlayerCommands.TargetPlayerFrame.UserName
local KickUser = script.Parent.PlayerCommands.CommandsList.KickUser
--
KickUser.MouseButton1Click:Connect(function()
	KickUser.Activated:Connect(function()
		UserKickEvent:FireServer(UserName.Text)
	end)
end)	

Server Script

--Service--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Locals--
local UserKickEvent = ReplicatedStorage.AdminEvents.UserKickEvent
--User Kick--
UserKickEvent.OnServerEvent:Connect(function(player, UserName)
	if not table.find(Admins, player.UserId) then
		return
	end
	local TargetUser = Players:FindFirstChild(UserName)
	if not TargetUser then
		return
	end
	player:Kick("You've been kick by an admin. Thanks for playing!")
end)
--Service--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Locals--
local UserKickEvent = ReplicatedStorage.AdminEvents.UserKickEvent
--User Kick--
UserKickEvent.OnServerEvent:Connect(function(player, UserName)
	if not table.find(Admins, player.UserId) then
		return
	end
	local TargetUser = Players:FindFirstChild(UserName)
	if not TargetUser then
		return
	end
	TargetUser:Kick("You've been kick by an admin. Thanks for playing!")
end)

Hey! I want to inform you that when you define OnServerEvent for anything, the first argument that is passed is ALWAYS the client that is sending the RemoteEvent (i.e., the admin). For this reason, when you do player:Kick() you are just kicking the admin. Change it to TargetUser:Kick() instead.

1 Like

This is the correct solution, I’m not sure why the other post was marked.

The other post was marked because in the function right above the end) I put player instead of TargetUser.

player:Kick("Kick") -- This would kick the admin. player is the admin
TargetUser:Kick("Kick") -- TargetUser is well the TargetUser

In this case both worked

Look at the first reply to your thread again, they call Kick() on the player instance which is referenced by the variable named “TargetUser”.