Issue with textbox?

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)

Maybe try replacing it with local InputName = script.Parent instead of local InputName = script.Parent.Name

That is the variable to link to the textbox, sorry for not clarifying

Then maybe try replacing that line with local PlayerToKick = Players:WaitForChild(Username)

No success, im not even getting anything in the output

Hi

Try instead of :WaitForChild() using :FindFirstChild() and then checking if the PlayerToKick is not nil.

	local PlayerToKick = Players:FindFirstChild(Username)
	if PlayerToKick == nil then print("player is nil") end

I tried this and i didn’t get any output,

Maybe because the PlayerToKick isn’t nil?

You can use GetUserIdFromNameAsync to replace with the

since that doesn’t make sense in this case you can use:

if Players:GetUserIdFromNameAsync(Username) ~= nil then

–your code

Thank you that seems a step in the right direction, now im getting this error: [Argument 1 missing or nil] in line 17 which is this line of code:

	if Players:GetUserIdFromNameAsync(Username) ~= nil then

Make sure the username variable gets the textbox.text

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)

The first steps

  • 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 :fire: :fire_engine: :fire: :fire_engine: (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! :slight_smile:

Useful links:

I just tried a quick Print(Username) It is nil, so i think the textbox is not working

Are you sure you changed inputName to script.Parent and that the parent of the script is the textbox?

do
local username = tostring(InputName.Text)

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

@Sougood
Yepp

@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

You might wanna fire the textbox text through a local script with the use of RemoteEvents

1 Like

You can’t do that, that isn’t how it works :sweat_smile:

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

1 Like