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

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

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

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.

0
But why does my script not work sometimes when I use game.Workspace.Part instead of script.Parent.Part? WelpNathan 307 — 10y
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. Spongocardo 1991 — 10y
0
@above Is correct. CheeseDevie 30 — 10y
0
Ahah! Thank you c; WelpNathan 307 — 10y
View all comments (2 more)
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 Tkdriverx 514 — 10y
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. FrontsoldierYT 129 — 4y
Ad

Answer this question