I think the issue is with the textbox. I’m trying to make an admin panel GUI which i plan to release for public use. I have inserted a normal script inside of the screen gui. You may think this is a silly reason, but it prevents having to do unnecessary time consuming checks on the events.
Anyway, i tried to do make a kick button and it will not work. I tried using a pcall for the kick and i’m getting no success, any help please
--// Services
local Players = game:GetService("Players")
--// Buttons etc
local InputName = script.Parent.Name
local KickButton = script.Parent.ScrollingFrame.Kick
local BanButton = script.Parent.ScrollingFrame.Ban
local WarnButton = script.Parent.ScrollingFrame.Warn
--// Others
local Player = script.Parent.Parent.Parent.Parent
KickButton.MouseButton1Click:Connect(function()
--// Checks
local Username = InputName.Text
if Username == nil then return end
local PlayerToKick = Players:WaitForChild(Username.Name)
local success, err = pcall(function()
PlayerToKick:Kick()
end)
if err then
print("Could not kick player, Make sure the username is typed correctly")
end
end)
KickButton.MouseButton1Click:Connect(function()
--// Checks
local Username = InputName.Text
if Username == nil then return end
local PlayerToKick = game.Players:FindFirstChild(Username)
if PlayerToKick ~= nil then
PlayerToKick:Kick()
end
end)
First of all, create a folder in replicatedStorage called “RemoteEvents”
Within that folder, create a remoteEvent called “AdminEvent”
In the client script: Define the Folder, Define the remoteEvent.
Next steps
So now, when a player clicks the KickButton Fire the server (AdminEvent:FireServer(“Kick”, Username")
On the server, detect when a client has called an event for the server to do! > AdminEvent.OnServerEvent:Connect(function(Player, Cmd, TargetPlayer)
Within this event, do all of the previous code above! (Or well, most of it - And you’ll be sorted!)
Although, a few if statements here and there ofc.
RemoteEvent.OnServerEvent:Connect(function(Player, Cmd, TargetPlayer)
if Cmd == "Kick" then
local PlayerToKick = Players:WaitForChild(TargetPlayer)
local success, err = pcall(function()
PlayerToKick:Kick()
end)
if err then
print("Could not kick player, Make sure the username is typed correctly")
end
end
Notes
Please read the links I’ve linked for you below, you must do this sort of stuff on the server - As if you want to kick a person from the client, you can’t. Unless you want to kick the local player.
All of this is explained below on why and how you should use it!
Hi, thank you but i’ve used a normal script in the gui as its less hassle and i can be 10000% sure that it cannot be exploited + Its what ive used for my other games, i know how to work remote events but i would prefer if it was also all in one script
@SaifLachmann
Another step closer, i now get my pcall error. I just checked the explorer textbox and it says no text is there, even though i already had typed something in the box
If you want to kick a player, you have to do it on the server. Just because you used a normal script on the client, doesn’t mean it will run it off the server. You have to use a local script & remoteEvents on the client and use remoteEvents on the server to achieve what you want to do