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

Not Getting Username/Player from text-box what do I do?

I have a situation where if I type a players username in the text-box the script is supposed to grab the player name I typed and go to Players and find the player and copy the tool in this case a coke into their backpack but I keep getting an error message on line 6.

Error Message From Console: Enter username is not a valid member of Players.

The text-box says Enter username but it shouldn't say error Enter username isn't a player when I changed the text to the players user already.

local a = game.ServerStorage.Items.Drinks -- Item Location

script.Parent.coke.MouseButton1Click:connect(function()
	if script.Parent.coke.Text == "Coke" then
		local new = a.Coke:Clone() -- Cloning Item
	new.Parent = game.Players[script.Parent.Username.Text].Backpack
	script.Parent.coke.Text = "Gave item!"
	wait(1)
	script.Parent.coke.Text = "Coke"
	end
end)

2 comments

0

The Text of Username is "Enter Username," you aren't actually specifying the Username.

0

Yes, cause the Roblox player is supposed to enter the username themselves its an editable text box so whatever name is inputed to the text box as long as their in the game it should grab them from Players.

1 answer

First of all :connect() is deprecated use :Connect() secondly input belongs on the client (localscript) and it doesnt work because when u make the changes to the textbox ur doing that as the client so the server doesnt have to changes, you ll have to use a localscript and a script and a remote event bewteen those

see remote events

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