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 4 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:

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).

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 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:

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.

1
thanks GravityGouse99938 75 — 4y
Ad

Answer this question