Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

NAME is not a valid member of Textbutton?

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

✓ Accepted answer

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

2 comments

0

Ah, thanks :) it all worked however i had to change it to a 'Script' instead of a 'Local Script'

0

Updated it so that it will tell you if the player doesn't exist

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!

2 comments

0

oh wow, xD thanks man! :D

0

However there was still an error when i used this :>

This discussion is preserved as it was. New answers, comments, and votes are closed.