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

RoboBug is not a part of Folder in OnTouched script?

Asked by 5 years ago

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:

01local robobug = script.Parent.Parent.Parent.RoboBug
02local h = robobug.humanoid
03local animation = robobug.Animate.walk.WalkAnim
04local animationTrack = h:LoadAnimation(animation)
05local eye1 = robobug.Eye1
06local eye2 = robobug.Eye2
07local e1 = robobug.e1
08local e2 = robobug.e2
09 
10function OnTouch()
11robobug.Animatronic_AI.Disabled = false
12animationTrack:Play()
13eye1.Color3 = e1.Value
14eye2.Color2 = e2.Value
15 
16end
17script.Parent.Touched:Connect(OnTouch)

(I know, maybe I'm big noob in coding, but please help).

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Issue

RoboBug is not a part of Folder But actually this model is inside of folder Here is the code

Solution

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:

1local robobug = script.Parent.Parent.Parent:WaitForChild("RoboBug")
2local 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.

1
thanks GravityGouse99938 75 — 5y
Ad

Answer this question