Hello. I am trying to make an elevator/lift using TweenService and WeldConstraints. However, sometimes the player just doesn’t get welded, or when the player tries to get out of the elevator/lift, they get teleported back to the lift.
THERE ARE NO ERRORS IN THE OUTPUT
-- Elevator
-- setup
local tween = game:GetService("TweenService")
local elevator = script.Parent
local canopen = true
local notMoving = false
-- tween setup
local eletweeninfo = TweenInfo.new(
10,
Enum.EasingStyle.Cubic,
Enum.EasingDirection.InOut,
0,
false,
0)
script.Parent.Touched:Connect(function(hit)
wait(1)
if hit.Parent.ClassName == "Accessory" then
local weld = Instance.new("WeldConstraint")
weld.Part0 = elevator
weld.Part1 = hit.Parent.Parent.HumanoidRootPart
weld.Parent = hit.Parent.Parent.HumanoidRootPart
repeat wait() until notMoving == true
hit.Parent.Parent.HumanoidRootPart.WeldConstraint:Destroy()
else
local weld = Instance.new("WeldConstraint")
weld.Part0 = elevator
weld.Part1 = hit.Parent.HumanoidRootPart
weld.Parent = hit.Parent.HumanoidRootPart
repeat wait() until notMoving == true
hit.Parent.HumanoidRootPart.WeldConstraint:Destroy()
end
end)
local TweenUp = tween:Create(elevator, eletweeninfo, {CFrame = elevator.Parent.TweenUpFloor.CFrame}) --tween "animation"
local TweenDown = tween:Create(elevator, eletweeninfo, {CFrame = elevator.Parent.TweenDownFloor.CFrame})
while true do
wait(5)
TweenDown:Play()
wait(10)
notMoving = true
wait(5)
notMoving = false
TweenUp:Play()
wait(10)
notMoving = true
end
Can anyone help?