I am trying to make a script that kicks people when the name is entered in a text box. However after multiple layouts and attempts they all end up saying "NAME is not a valid member of Textbutton" please help because I am very stuck :) Thanks!
So the structure of my layout is
/> AdminGUI
/>ClickKick --Text Button
/>LocalScript
/>NAME -- Text Box
And the code is
local PLAYERNAME = script.Parent.NAME.Text function click() game.Players.PLAYERNAME:Kick("Kicked by server admin") end script.Parent.MouseButton1Down:connect(click)
My guess is that NAME is somehow being mixed up with Name
I would suggest renaming it to something else for example 'PlayerName"
Also you should make sure that the player exist before kicking them.
Edit: Updated it so that it will tell you if the player doesn't exist
Example Structure:
--AdminGUI --ClickKick --Text Button --LocalScript --LocalScript --PlayerName -- Text Box
Script:
function click() local PlayerName = script.Parent.PlayerName if game:GetService("Players"):FindFirstChild(PlayerName.Text) then game.Players[PlayerName.Text]:Kick("Kicked by server admin") else PlayerName.Text = "Player doesn't exist" end end script.Parent.MouseButton1Down:connect(click)
Not tested but it should work
The script may be loading before the GUI does.
To fix this, you need to wait until the button exists with WaitForChild()
:
local PLAYERNAME=script.Parent:WaitForChild("NAME").Text function click() game.Players[PLAYERNAME]:Kick("Kicked by server admin") end script.Parent.MouseButton1Down:connect(click)
You may have also noticed that I put PLAYERNAME in brackets on line 3. This is so the script knows to use the variable instead of looking for a player named "PLAYERNAME".
I hope this helped!