What I want to do is create a simple platform that tweens up when a button is pressed, and down when another one is pressed. I have gotten the going up part working, but the going down aspect of it doesn’t seem to work. This is the code I’m using, and even though the second tween has its Y set to a - number, it still goes up when the button is pressed. How can I make it go down?
local TweenService = game:GetService("TweenService")
local elev = script.Parent.elevator.Platform
local tweenInfo = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local tween = TweenService:Create(elev, tweenInfo, {Position = elev.Position + Vector3.new(0, 43.8, 0)})
script.Parent.downbutton.UP.ClickDetector.MouseClick:Connect(function(plr)
script.Parent.elevator.Click:Play()
tween:Play()
wait(3.5)
elev.Anchored = true
wait(0.1)
script.Parent.elevator.Blocker1.CanCollide = true
script.Parent.elevator.Blocker3.CanCollide = false
local tween2Info = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tween2 = TweenService:Create(elev, tween2Info, {Position = elev.Position - Vector3.new(0, -43.8, 0)})
script.Parent.downcall.downcall.ClickDetector.MouseClick:Connect(function(plr)
script.Parent.elevator.Click:Play()
tween2:Play()
wait(3.5)
elev.Anchored = true
wait(0.1)
script.Parent.elevator.Blocker1.CanCollide = false
script.Parent.elevator.Blocker3.CanCollide = true
end)
end)
Two negatives make a positive my man.
what do you mean by that? I only have one negative in the script
You were using a negative for a negative number, which turns into a positive number. That’s why your second tween wasn’t going downwards.
Here is your fixed code:
local TweenService = game:GetService("TweenService")
local elev = script.Parent.elevator.Platform
local tweenInfo = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local tween = TweenService:Create(elev, tweenInfo, {Position = elev.Position + Vector3.new(0, 43.8, 0)})
script.Parent.downbutton.UP.ClickDetector.MouseClick:Connect(function(plr)
script.Parent.elevator.Click:Play()
tween:Play()
wait(3.5)
elev.Anchored = true
wait(0.1)
script.Parent.elevator.Blocker1.CanCollide = true
script.Parent.elevator.Blocker3.CanCollide = false
local tween2Info = TweenInfo.new(3.0, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tween2 = TweenService:Create(elev, tween2Info, {Position = elev.Position + Vector3.new(0, -43.8, 0)}) -- you have used a negative here
script.Parent.downcall.downcall.ClickDetector.MouseClick:Connect(function(plr)
script.Parent.elevator.Click:Play()
tween2:Play()
wait(3.5)
elev.Anchored = true
wait(0.1)
script.Parent.elevator.Blocker1.CanCollide = false
script.Parent.elevator.Blocker3.CanCollide = true
end)
end)
1 Like
Did you play the tweens? You can use Tween:Play()
.
and yes the position is most likely incorrect. It’s negative.
you had -43.8 and -, try adding instead.
1 Like
Oh I see what I did wrong. Thanks for the help!
2 Likes