Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When i press a key my door doesnt open?

Asked by 1 year ago

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)

0
Are there any errors in output/does it print "test"? virushunter9 943 — 1y
0
Try creating the Animation, AnimationController, and Animator in the Door manually and not by script. T3_MasterGamer 2189 — 1y
0
it seem you have a duplicate code at the top as Door and target door vales are the same Xx_ashcarter13 17 — 1y
0
i will test all of these thank you! PeterParker17386 16 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

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!

Ad

Answer this question