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

How to display part name on Text GUI?

Asked by 4 years ago

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
0
Could you provide an image of the "Explorer" tab of your Roblox Studio? I think that would help pinpoint the problem here. DemonHunterz6 35 — 4y
0
Thoroughly check through your "Parents" and "Childs" to make sure that they all line up, if that helps. DemonHunterz6 35 — 4y
0
here, i think its correct. either that or im being dumb ahah https://i.imgur.com/0I2wRPh.png flufffybuns 89 — 4y

2 answers

Log in to vote
1
Answered by
oilkas 364 Moderation Voter
4 years ago

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
Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question