How to get model name identified in a script?

Hello! I am trying to find out how I can identify a models name in my script, and then turn a text into the models name.

Here is my code:

text = script.Parent
model = text.Parent.Parent


text.TextLabel = model....???

This should be simple but somehow I forgot. Thanks.

Hey! You should be able to use model.Name, however I see another error in your code.
You refer to the text as the “Textlabel”, but that isn’t where the text is stored. you could try this:

local textLabel = script.Parent
local model = textLabel.Parent.Parent

textLabel.Text = model.Name
2 Likes

you should try this

text = script.Parent.Text --i suppose that this is a some sort of a gui
model = text.Parent.Parent

text = model.Name

Oh yeah, something I forgot to say is that you didn’t put local in front of your variables, You should always do this.
You can read this post on why:

1 Like

oh i didnt realize that either xd

Hey, hope you’re well! I’m assuming you’re using a GUI to do this?

There’s a few errors in your script! The first one is your variables, as Blauwemelluk said, you should have local infront of them. The second one is that you have no function!

I’ve put together some code that changes the TextLabel whenever a TextButton is clicked!

local Text = script.Parent.TextLabel --// The Text property within a TextLabel
local Button = script.Parent.TextButton --//  TextButton
local Model = workspace.Test --//  The model that we're taking the name from.

Button.MouseButton1Click:Connect(function() --//  Running the code below when the 'Button' is clicked.
	Text.Text = Model.Name --//  Setting the Text within the TextLabel to the name property of the Model.
end)

Hope this helps!

1 Like

Every object in your game has properties, these properties are things that adjectives that describe or make your object what it is. For instance, a property of a part could be the ‘Transparency’ which determines how visible a part is.

In summary, when you look at your model for example you will see properties on the property window. (View > Properties) There you will see a bunch of properties including the ‘Name’ property.

So to call a property you would have to do this.

Object.Name
Object.Transparency
Object.BrickColor

All of those are properties within an object.

Hope this helped.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.