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.
--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.