I’m new to scripting and I am trying to make a remote event to kick Players. I can see what the problem is (I think) is that I’m not referencing the player but I don’t know how if anybody could help me.
Script:
game.ReplicatedStorage.Kick.OnServerEvent:Connect(function(Player)
Player:Kick(“You’re not welcome here at the moment. :)”)
end)
for variable9, variable10 in pairs(Players:GetChildren()) do
if string.lower(refer) == string.lower(string.sub(variable10.Name, 1, string.len(refer))) then
Kick:FireServer(variable10);
btw I don’t know what to name variables so I’m messy
Refer is
local refer = string.sub(Text, string.len(":kick ") + 1)
I’m making an admin commands gui and since regular script didn’t work I’m using local script and I just found out you needed remote events since it didn’t work without them
You don’t need the variable10 in the FireServer part. Also I would highly, highly suggest giving your variables way better and more descriptive names, as this is pretty much impossible to understand without background context.
Secondly, what you’re doing right now will kick whoever fired the RemoteEvent, which probably isn’t what you want, so you’ll need to pass the text ox’s text through the RemoteEvent as well, then receive it on the ServerSide.
local Players = game:GetService("Players")
game.ReplicatedStorage:WaitForChild("Kick").OnServerEvent:Connect(function(Player)
if Players:FindFirstChild(Player) then
Player:Kick("Your access to this experience has been denied!")
end
end)
Make sure to utilize sanity checks, to make sure the player object exists! Remember, exploiters can access remotes, meaning if they fire it, the remote may not pass the player parameter.
Sever script basically just connections to your message and check if the prefix is stated (you can add if it's admin only) and then finds the player name and kicks 'em!.
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
print("messaged")
local function Kick(message)
local test = message
local player
local first
local second
local third
if test:sub(0,6):match("/kick:") then
print("prefix is correct")
for i,v in pairs(game:GetService("Players"):GetChildren()) do
first = string.find(test, " ")
if first == 7 then
second = string.sub(test, 8, 99)
else
second = string.sub(test, 7, 99)
end
third = string.match(v.Name:lower(), second)
if third then
player = v
player:Kick("Bye")
end
end
else
end
end
-- you most likely want this to be admin based to just delete the first "--" below
-- if table.find(Table, plr.UserId) then -- replace Table with your table filled with admin userid's
Kick(msg)
-- end -- yeah delete these "--" in front of the end
end)
end)