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:
local robobug = script.Parent.Parent.Parent.RoboBug local h = robobug.humanoid local animation = robobug.Animate.walk.WalkAnim local animationTrack = h:LoadAnimation(animation) local eye1 = robobug.Eye1 local eye2 = robobug.Eye2 local e1 = robobug.e1 local e2 = robobug.e2 function OnTouch() robobug.Animatronic_AI.Disabled = false animationTrack:Play() eye1.Color3 = e1.Value eye2.Color2 = e2.Value end 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:
local robobug = script.Parent.Parent.Parent:WaitForChild("RoboBug") local h = robobug:WaitForChild("Humanoid") --// 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.