Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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"
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

1 comment

0

Holy mother of unreadable code. Please indent your code.

2 answers

✓ Accepted answer

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.

2 comments

0

I really can't use tweenservice since the doors push out backwards and then open.

0

The correct answer really was that animations can only be triggered on events.

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?

3 comments

0

Can you explain your code instead of just posting a script?

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.

0

The animations are fully working, I've checked

This discussion is preserved as it was. New answers, comments, and votes are closed.