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 7 years ago
Edited 7 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

local PLAYERNAME = script.Parent.NAME.Text
function click()
game.Players.PLAYERNAME:Kick("Kicked by server admin")

end


script.Parent.MouseButton1Down:connect(click)

2 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 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:

--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

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

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!

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

Answer this question