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

How to display part name on Text GUI?

I have a script that's supposed to display a parts name in a text GUI. This is particularly useful because the name could be different every time. However, I always get returned with "bad argument #3 (string expected, got nil)"

local name = game.Workspace.key.part.Name

wait(0.2) -- ignore this

script.Parent.dialogue.Text = name

3 comments

0

Could you provide an image of the "Explorer" tab of your Roblox Studio? I think that would help pinpoint the problem here.

0

Thoroughly check through your "Parents" and "Childs" to make sure that they all line up, if that helps.

0

here, i think its correct. either that or im being dumb ahah https://i.imgur.com/0I2wRPh.png

2 answers

You can try to fix this by not directly assigning properties and yielding. This code here should work:

local Key = game.Workspace:WaitForChild("key")
local Part = Key:FindFirstChild("part")

if Part then
	script.Parent.dialogue.Text = Part.Name
end

It seems you might have an extra property in your variable, so try:

local name = game.Workspace.key.Name

Or try:

local name = game.Workspace.part.Name

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