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

How to make a door smoothly go up after it is already down?

Yooo, so I am making a game where you press a button and a door goes down and when you press it the second time, the door goes up.... but I have no idea how to make it go up after it goes down.

Here is the script to make the door go down

local part = game.Workspace.Door1 local ClickDetector = Instance.new("ClickDetector") local TweenService = game:GetService("TweenService") ClickDetector.Parent = script.Parent ClickDetector.MouseClick:Connect(function()

local goal = {}
goal.Position = Vector3.new(part.Position.X, part.Position.Y-10, part.Position.Z)

local tweenInfo = TweenInfo.new(1)

local tween = TweenService:Create(part, tweenInfo, goal)

tween:Play()

end)

1 comment

0

Idk Why the script appears like 2 parts, the part above the actual script is part of the script as well

3 answers

You can have a variable that changes when it goes up and then down.

local Variable == up
ClickDetector.MouseClick:Connect(function()
	if Variable == up then
		Variable = down
		local goal = {}
		goal.Position = Vector3.new(part.Position.X, part.Position.Y-10, part.Position.Z)
	 
		local tweenInfo = TweenInfo.new(1)
	 
		local tween = TweenService:Create(part, tweenInfo, goal)
	 
		tween:Play()
	elseif Variable == down then
		Variable = up
		local goal = {}
		goal.Position = Vector3.new(part.Position.X, part.Position.Y+10, part.Position.Z)
		 
		local tweenInfo = TweenInfo.new(1)
	 
		local tween = TweenService:Create(part, tweenInfo, goal)
	 
		tween:Play()
	end
end)
local Variable == up
ClickDetector.MouseClick:Connect(function()
    if Variable == up then
        Variable = down
        local goal = {}
        goal.Position = Vector3.new(part.Position.X, part.Position.Y-10, part.Position.Z)

        local tweenInfo = TweenInfo.new(1)

        local tween = TweenService:Create(part, tweenInfo, goal)

        tween:Play()
    elseif Variable = down then
        Variable = up
        local goal = {}
        goal.Position = Vector3.new(part.Position.X, part.Position.Y+10, part.Position.Z)

        local tweenInfo = TweenInfo.new(1)

        local tween = TweenService:Create(part, tweenInfo, goal)

        tween:Play()
    end
end)

This is the same as @Justin's exepct Without the two equal Signs

I keep getting this error when using your idea @Justin

Workspace.Part.Script:5: Expected identifier when parsing expression, got '=='

1 comment

0

I didn't mean to put 2 equal signs on the first line. Just remove one of them

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