Your explanation was not very clear. Consider describing what exactly you meant by the "because that's not in PlayerGUI. How do I redirect that back to the Light part?".
I do not understand how you meant the Light
part had Changed?
Which is why this is probably not even the answer you are looking for but nevertheless, it has some useful suggestions for future. Comment on the answer below if this was not the solution you wanted. You do not need to create a new answer to post a comment but merely write your comment on the comment bar which is below every answer.
The first thing you have to do is stay organized. The reason why you are running into errors is that you are not organized.
Here are some ways in which you can improve your Model
.
- Name the
Model
. What is the Model
? A car? If so, name it Car_Model
.
- It is also a good practice to name the
script
as well.
- Again, rename your
SurfaceGui
to what it is actually about.
- Rename the
Sound
to what it is, i.e. Honk, Brake etc.
That is pretty much the complaints I have in Models. I do, however, have a lot for the scripts.
- Since you are using quite a lot of
Parent
, consider actually writing each one out as a variable.
03 | local Workspace = game:GetService( "Workspace" ); |
06 | local Car_Model = Workspace.Car_Model; |
07 | local Seat 1 = Car_Model.Seat 1 ; |
08 | local Message_Gui = Seat 1 :WaitForChild( "MessageGui" ); |
09 | local Light = Car_Model.Light; |
10 | local Surface_Gui = Car_Model:WaitForChild( "SurfaceGui" ); |
11 | local Sound = Light:WaitForChild( "Sound" ); |
The above method is my preferred way. Any person who looks at my code can immediately identify things without the need to add a picture to describe those Parent
s. Of course you are eligible to use Parent
s. You are using 5 Parent
in this case, which is not a good idea.
connect:
is depreciated. Consider switching over to Connect:
. It is just a capital C. It won't hurt to switch over.
Now you did say rest of the stuff works so I won't do much there. You, however, have not posted what exactly you cloned. Did you clone the whole Model?, Did you clone the script?. What exactly did you clone? Put more information on that. I am going to continue on assuming you cloned Message_Gui
You said,
You know when this script has been cloned to the PlayerGUI, the "script.Parent.Parent.Parent.Parent.Parent.Light" has changed because that's not in PlayerGUI.
From my understanding, it looks like the Light
part's location breaks off.
Why?
Well you said Light = script.Parent.Parent.Parent.Parent.Parent.Light
, you declared Light
from the LocalScript
. Now when the LocalScript
is moved to the PlayerGui
, the script will not find the Light
because it will look at all the Parent
's and find that there is not Light
Part anywhere.
Solution.
Now, in cases like this, you want to declare the Light
after the script has been cloned or simply, declare it from top to bottom. Which is why, you don't want to use Parent
's in these cases.
03 | local Workspace = game:GetService( "Workspace" ); |
06 | local Car_Model = Workspace.Car_Model; |
07 | local Seat 1 = Car_Model.Seat 1 ; |
08 | local Message_Gui = Seat 1 :WaitForChild( "MessageGui" ); |
09 | local Light = Car_Model.Light; |
10 | local Surface_Gui = Car_Model:WaitForChild( "SurfaceGui" ); |
11 | local STextbox = Surface_Gui:WaitForChild( "TextLabel" ); |
12 | local Sound = Light:WaitForChild( "Sound" ); |
19 | Light.Material = Enum.Material.Neon; |
20 | STextbox = "Stop Request" ; |
21 | Message_Gui.Enabled = false ; |
25 | STextbox.MouseButton 1 Down:Connect(Gui_Stuff); |
Do not copy the above script. Simply use it as a reference because it may not work like how you desire. You will most probably also run into a problem of working only in studio. This is fixable by using Remote Events and Function which I will leave the links down below. I suggest you check them out.
So why will this method work in studio
- I declared variables properly.
- Using the
Parent
was the reason you could not do the stuff inside the function. I went from game
to Workspace
. Then I went downt to Car_Model
. Then I went to Light
. Now the Message_Gui
is already cloned and in my way, the Light
has nothing to do with Message_Gui
. Thus, it works.
- I was organized.
- The code may have more lines than before but It is readable. Now, the Computer does not care how messy you right. But since you were not able to debug properly, writing in a organized way is a must.
Well I am getting bored of writing and writing now and I will close this answer with some helpful resources you can check out.
Useful Resources to Study more on.
Should you have any questions, feel free to comment below, not create a new answer. Have fun debugging.