Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

NAME is not a valid member of Textbutton?

Asked by 8 years ago
Edited 8 years ago

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

1local PLAYERNAME = script.Parent.NAME.Text
2function click()
3game.Players.PLAYERNAME:Kick("Kicked by server admin")
4 
5end
6 
7 
8script.Parent.MouseButton1Down:connect(click)

2 answers

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

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:

01function 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
08end
09 
10 
11script.Parent.MouseButton1Down:connect(click)

Not tested but it should work

0
Ah, thanks :) it all worked however i had to change it to a 'Script' instead of a 'Local Script' Karl_RBX 11 — 8y
0
Updated it so that it will tell you if the player doesn't exist shadownetwork 233 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

The script may be loading before the GUI does. To fix this, you need to wait until the button exists with WaitForChild():

1local PLAYERNAME=script.Parent:WaitForChild("NAME").Text
2function click()
3    game.Players[PLAYERNAME]:Kick("Kicked by server admin")
4end
5script.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!

0
oh wow, xD thanks man! :D Karl_RBX 11 — 8y
0
However there was still an error when i used this :> Karl_RBX 11 — 8y

Answer this question