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

When i press a key my door doesnt open?

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)

4 comments

0

Are there any errors in output/does it print "test"?

0

Try creating the Animation, AnimationController, and Animator in the Door manually and not by script.

0

it seem you have a duplicate code at the top as Door and target door vales are the same

0

i will test all of these thank you!

1 answer

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!

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