So I’m working on an admin panel for my game, and obviously it needs a kick system. But this is my first time making my own admin (when I first started out I used kohl’s admin). Here’s the script I have right now:
--local script inside kick button
local Players = game:GetService("Players")
local Player = Players.KickTextbox --KickTextbox is where the admin will put the username of the player they want to kick
script.Parent.MouseButton1Click:Connect(function()
Players.Name:Kick(script.Parent.Parent.ModMessageTextbox.Text) --ModMessageTextbox is where the admin will put the moderation message
end)
I cant figure how to do this. If anyone could help that would be awesome. Thanks!
I think you can’t kick a player from the client, so use remote event, send a request to the server, and connect the function on the server (the first argument is the player) and kick the player already on the server.
Of course, the server Script Service
P.S: by the way, the script that I provided is complete bullshit. Remote events can be faked. never trust a client. However, it solves your problem, so it’s OK.
Yeah that’s what I assumed. I’m going to test if it works now.
Edit: It doesn’t work correctly. It always kicks me when I input a name to kick someone else and doesn’t let me input the moderation message (its always “lol”). Here’s the scripts I used, tell me if i did somthing wrong:
--Local Script inside the kick button
local Event = game.ReplicatedStorage.KickEvent
script.Parent.MouseButton1Click:Connect(function()
Event:FireServer("lol")
end)
--Server Script inside ServerScriptService
local Event = game.ReplicatedStorage.KickEvent
Event.OnServerEvent:Connect(function(player, text)
player:Kick(text or "lol")
end)
you didn’t think it would work correctly out of the box, did you? I just showed you how it should work approximately, the so-called boiler plate. And now I’m going to cry, because the gpt chat is the only thing that will probably help you.
That said, for the UI side of things, it might be nice to have a list of players currently in the server. This would just be Players.PlayerAdded and Players.PlayerRemoving, but it would be more overhead compared to just putting in the Name of the player.
If you have a ban list, make sure you use the UserId of the player and not their Name or Display name. This is because the names can be changed. For in-game kicking though, it should be perfectly fine to go based on the Name.
Very important that you do sanity checks with this to prevent problems later
Server script
--USE USERID NAMES CAN BE CHANGED BUT NOT ID
local operators={} --everyone with permits goes here
game.Players.PlayerAdded:Connect(function(player)
If table.find(operators,player.UserID) then
local kickUi=game.ServerStorage.KickGui:Clone()
--On server storage so hackers can't see it in replicated storage
kickUi.parent=player.PlayerGui
end
end)
Now on a LocalScript (parented under the Gui)
--I'm just gonna do it the short way, definitely could be way cleaner
script.Parent.Button.MouseButton1Click:Connect(function()
local kickingName=script.Parent.Player.Text
--Textbox instance for this example
Local reason=script.Parent.Reason.Text
--Also a textbox
game.ReplicatedStorage.KicEvent:FireServer(kickingName,reason)
--Of course change this to fit your configuration
end)
Now back to a server script the same or another it doesn’t matter (you do need the operators still)
game.ReplicatedStorage.KickEvent.OnServerEvent:Connect(function(player,kickingPlayer,reason)
--VERY IMPORTANT WE DON'T WANT NON OPERATORS TO BE ABLE TO KICK
if not table.find(operators,player.UserID) then
warn(player.Name.." Is not an operator and tried to access admin functions")
end
local toKick=game.Players:FindFirstChild(kickingPlayer)
If toKick then
toKick:Kick(reason or " ")
end
end)
There’s most of it and is like really rudimentary but that’s the very basics of it
--client
local Event = game.ReplicatedStorage.KickEvent
Event:FireServer(PlayerToKick,"lol")
```lua
--server
local Event = game.ReplicatedStorage.KickEvent
Event.OnServerEvent:Connect(function(player,PlayerToKick, text)
if not Players:FindFirstChild(PlayerToKick.Name) then return end
-- !!! here I strongly recommend using validation. !!!
--[[
In general, I generally do not recommend using such scripts. A cheater will come in and boom, all the players are kicked!
--]]
PlayerToKick:Kick(text or "lol")
end)
Now think about how you can receive PlayerToKick and Text on the client - the correct answer is through a TextBox or creating a drop-down list with different values.
A drop down lists definitely the way, it’s easier to use it and avoids being disrupted by those annoying names like lililllIIIlIIl and stuff, it’s not very hard to make, but I’m typing this on mobile so I wasn’t willing to write all that.
TL;DR: Make a drop down list for you and any moderators sake
UserID is not a valid member of Player “Players.jilly3678” and Button is not a valid member of Frame “Players.jilly3678.PlayerGui.AdminUi.AdminPanel”. I would ask how to make the dropdown menu, but you already explained you’re on mobile. I’ll ask someone else.
Edit: OH I SEE I FORGOT TO CHANGE THE NAME OF THE BUTTON IN THE SCRIPT
--USE USERID NAMES CAN BE CHANGED BUT NOT ID
local operators={3381926430} -- UR USERID
local function validateInstance(instance: Instance, expectedClass: string): boolean
if typeof(instance) ~= "Instance" then return false end
if not instance then return false end
return instance:IsA(expectedClass)
end
game.Players.PlayerAdded:Connect(function(player)
if not table.find(operators,player.UserId) then return end
local kickUi = game.ServerStorage.KickGui:Clone()
kickUi.Parent = player.PlayerGui
end)
game.ReplicatedStorage.KickEvent.OnServerEvent:Connect(function(player,kickingPlayer,reason)
if not table.find(operators,player.UserId) then player:Kick("U havent permission, so, its why u get kicked") return end
local toKick = game.Players:FindFirstChild(kickingPlayer)
if not validateInstance(toKick,"Player") then return end
toKick:Kick(reason or " ")
end)
-- its server
script.Parent.Button.MouseButton1Click:Connect(function()
local kickingName = script.Parent.Player.Text
local reason=script.Parent.Reason.Text
game.ReplicatedStorage.KickEvent:FireServer(kickingName,reason)
end)
-- its client
I can’t provide full code for that but you have to iterate through all players in the server, and add a button for each one of them, and then do it again for when a new player is added, and remove the button when the player is removed (done all in the server script), for the gui list you can conveniently use a UiList and just organize alphabetically (the order is based on instance names not text content)