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
1 | local PLAYERNAME = script.Parent.NAME.Text |
2 | function click() |
3 | game.Players.PLAYERNAME:Kick( "Kicked by server admin" ) |
4 |
5 | end |
6 |
7 |
8 | script.Parent.MouseButton 1 Down: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:
1 | --AdminGUI |
2 | --ClickKick --Text Button |
3 | --LocalScript --LocalScript |
4 | --PlayerName -- Text Box |
Script:
01 | function click() |
02 | local PlayerName = script.Parent.PlayerName |
03 | if game:GetService( "Players" ):FindFirstChild(PlayerName.Text) then |
04 | game.Players [ PlayerName.Text ] :Kick( "Kicked by server admin" ) |
05 | else |
06 | PlayerName.Text = "Player doesn't exist" |
07 | end |
08 | end |
09 |
10 |
11 | script.Parent.MouseButton 1 Down: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()
:
1 | local PLAYERNAME = script.Parent:WaitForChild( "NAME" ).Text |
2 | function click() |
3 | game.Players [ PLAYERNAME ] :Kick( "Kicked by server admin" ) |
4 | end |
5 | script.Parent.MouseButton 1 Down: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!