If someone could tell me what I did wrong with the code below, I would appreciate it.
local leftDoor = script.Parent.LeftDoor:GetChildren()[1] leftDoor.PrimaryPart.Anchored = true local rightDoor = script.Parent.RightDoor:GetChildren()[1] rightDoor.PrimaryPart.Anchored = true local humanoidLeft = leftDoor:FindFirstChildOfClass("Humanoid") local humanoidRight = rightDoor:FindFirstChildOfClass("Humanoid") humanoidLeft:Destroy() humanoidRight:Destroy() local animationControllerLeft = Instance.new("AnimationController", leftDoor) local animationControllerRight = Instance.new("AnimationController", rightDoor) local animationLeft = Instance.new("Animation", leftDoor) local animationRight = Instance.new("Animation", rightDoor) animationLeft.AnimationId = "http://www.roblox.com/asset/?id=2961216872" animationRight.AnimationId = "http://www.roblox.com/asset/?id=2961217745" local animationTrackLeft = animationControllerLeft:LoadAnimation(animationLeft) local animationTrackRight = animationControllerRight:LoadAnimation(animationRight) if script.Parent.MotionDetector1.IsDetected.Value == true or script.Parent.MotionDetector2.IsDetected.Value == true then animationTrackLeft:Play() animationTrackRight:Play() end
Well for one you should use an Animation Controller if you want to go that route, and instead of an Instance.new() just make it in the model or put it in ReplicatedStorage. Second, You would be better off using TweenService instead of an animation.
local leftDoor = script.Parent.LeftDoor:GetChildren()[1] leftDoor.PrimaryPart.Anchored = true local rightDoor = script.Parent.RightDoor:GetChildren()[1] rightDoor.PrimaryPart.Anchored = true local humanoidLeft = leftDoor:FindFirstChildOfClass("Humanoid") local humanoidRight = rightDoor:FindFirstChildOfClass("Humanoid") humanoidLeft:Destroy() humanoidRight:Destroy() local animationControllerLeft = Instance.new("AnimationController", leftDoor) local animationControllerRight = Instance.new("AnimationController", rightDoor) local animationLeft = Instance.new("Animation", leftDoor) local animationRight = Instance.new("Animation", rightDoor) animationLeft.AnimationId = "http://www.roblox.com/asset/?id=2961216872" animationRight.AnimationId = "http://www.roblox.com/asset/?id=2961217745" local animationTrackLeft = animationControllerLeft:LoadAnimation(animationLeft) local animationTrackRight = animationControllerRight:LoadAnimation(animationRight) if script.Parent.MotionDetector1.IsDetected.Value == true or script.Parent.MotionDetector2.IsDetected.Value == true then animationTrackLeft:Play() animationTrackRight:Play() end
Better?