I made an animation for a door opening and when i write a script for it, it doesnt work. It definitely detects when i press a key but it doesnt open the door. My script:
local Players = game:GetService("Players") local Player = Players.LocalPlayer local Button = game.Workspace.DoorFolder.Door.Prompt.TextButton local key = game:GetService("UserInputService") local TweenService = game:GetService("TweenService") local info = TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0) local EndGoal = {Orientation = Vector3.new(0, -158.659, 0); } local Door = game.Workspace.DoorFolder.Door local TargetDoor = game.Workspace.DoorFolder.Door local DoorAnimation = Instance.new("Animation") DoorAnimation.AnimationId = "http://www.roblox.com/asset/?id=11962577878" DoorAnimation.Parent = game.Workspace.DoorFolder.Door key.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.E then local animationController = Instance.new("AnimationController") animationController.Parent = DoorAnimation.Parent local animator = Instance.new("Animator") animator.Parent = animationController local DoorAnimationTrack = animator:LoadAnimation(DoorAnimation) DoorAnimationTrack:Play() print("test") end end)
Try using tween service instead of using an animation, usually also check if ur animation ID is incorrect.. You never know. anyway heres how to create a tween.
local tweenservice = game:GetService("TweenService") local tweeninfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 1, false) local tween = tweenservice:Create(the door here, tweeninfo, goal here means a property change to reach)
now let me explain.
im creating a tween that has the parameters of door, tweeninfo, and a goal However u dont need to udnerstand fully.
u would use tween:Play()
to run it.
if u want to wait until a tween is done do this after u play it.
tween.Completed:Wait()
I hope this helps!