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

Can you tell me the difference between script.Parent.Part & game.Workspace.Part?

Hello, just a quick question what I would you to answer please c;

I have used scripts mainly using things like this: game.Workspace.Part.SpotLight.Enabled = true. what work fine.

But sometimes I can't get some things like game.Workspace.Something.Something to work. Therefore turning to script.Parent.Parent.Something.Something. Therefore making it work o-o

Can you please tell me the difference? :D

Thanks, Mc.

1 answer

✓ Accepted answer

It all depends on what you want, I can't really think of a correct way to answer this but let me make a few examples!

Pretend there is a script within a part, you want to access the part property's. So in this example we are going to change the transparency of the part.

script.Parent.Transparency = 0.5

This is a short cut from going:

game.Workspace.Part.Transparency = 0.5

It really depends, in Lua you !NEED! to make short cuts to make your life much more easy.

If you're in a game script in Workspace and you need to access a part (That you will be accessing regularly), you can make 'Variables' example:

Part = game.Workspace.Part
Part.Transparency = 0.5

I wont get into Local Variables.

I hope this helped.

6 comments

0

But why does my script not work sometimes when I use game.Workspace.Part instead of script.Parent.Part?

1

Probably because the part is not available when the Workspace is. The script's parent is made before the script, so script.Parent.Part will work.

0

@above Is correct.

0

Ahah! Thank you c;

0

Probably because script.Parent.Part doesn't exist, while game.Workspace.Part does. To get the part the script is in, it's just script.Parent

0

If your doing script.Parent.Part then you are accessing a part inside the Instance. If you are doing script.Parent then that is the Parent of the script.

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