Still have questions? Join our Discord server and get real time help.
0

# What's wrong with this animation playing script for my sliding doors?

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"
if script.Parent.MotionDetector1.IsDetected.Value == true or script.Parent.MotionDetector2.IsDetected.Value == true then
animationTrackLeft:Play()
animationTrackRight:Play()
end

0

0

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.

0
I really can't use tweenservice since the doors push out backwards and then open. 0a0_game -3 — 2mo
0
The correct answer really was that animations can only be triggered on events. 0a0_game -3 — 2mo
0
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"
if script.Parent.MotionDetector1.IsDetected.Value == true or script.Parent.MotionDetector2.IsDetected.Value == true then
animationTrackLeft:Play()
animationTrackRight:Play()
end


Better?

0
Can you explain your code instead of just posting a script? theking48989987 1767 — 2mo
0
Line 1 through 4 gets the parts of the doors and anchors the main part, line 5 through 10 replaces the humanoid in the doors with an animtgationController which is required to animate non-humanoid objects, line 11 through16 loads the animations into the animation controllers and line 17 till line 20 makes sure that if either of the IsDetcted properties are true both animations play. 0a0_game -3 — 2mo
0
The animations are fully working, I've checked 0a0_game -3 — 2mo