Hello. i need to play animation and change object, but i got: ``RoboBug is not a part of Folder But actually this model is inside of folder Here is the code:
01 | local robobug = script.Parent.Parent.Parent.RoboBug |
02 | local h = robobug.humanoid |
03 | local animation = robobug.Animate.walk.WalkAnim |
04 | local animationTrack = h:LoadAnimation(animation) |
05 | local eye 1 = robobug.Eye 1 |
06 | local eye 2 = robobug.Eye 2 |
07 | local e 1 = robobug.e 1 |
08 | local e 2 = robobug.e 2 |
09 |
10 | function OnTouch() |
11 | robobug.Animatronic_AI.Disabled = false |
12 | animationTrack:Play() |
13 | eye 1. Color 3 = e 1. Value |
14 | eye 2. Color 2 = e 2. Value |
15 |
16 | end |
17 | script.Parent.Touched:Connect(OnTouch) |
(I know, maybe I'm big noob in coding, but please help).
RoboBug is not a part of Folder But actually this model is inside of folder Here is the code
The problem is probably because the instance does not exist before the code therefore when the code looks for it then it will throw an error.
Use WaitForChild
which is a member of all Instance
types.
https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild
Example:
1 | local robobug = script.Parent.Parent.Parent:WaitForChild( "RoboBug" ) |
2 | local h = robobug:WaitForChild( "Humanoid" ) |
3 |
4 | --// and so on |
If this doesn't work then you probably identified the location to RoboBug
incorrectly. Make sure to start at your script and visually work up one level every .Parent
and then back down if you index something inside the parent.