Elevator script not working

Hey,

Basically: I made an elevator for my game, but there are no errors and it doesn’t move. I’m just really getting annoyed by it and thought the devs on devforum could help.

Error: (well, not really an error. But it’s not tweening.)

--CALL ELEVATOR (FIRST BUTTON IN THE VIDEO)
local ts = game:GetService("TweenService")
local d = true

script.Parent.ProximityPrompt.Triggered:Connect(function()
	
	if d == true then
		d = false
		
		ts:Create(script.Parent.Parent.Elevator.Door, TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = script.Parent.Parent.Elevator.NormalPos.Position}):Play()
		
		script.Parent.ProximityPrompt.Enabled = false
		script.Parent.Parent.Elevator.SignalEleButton.ProximityPrompt.Enabled = false
		
		wait(3)
		
		script.Parent.Parent.Elevator.SignalEleButton.ProximityPrompt.Enabled = true
		
		d = true
		
	end
	
end)
--SIGNALELEBUTTON (2ND BUTTON YOU SAW IN THE VIDEO)
local ts = game:GetService("TweenService")
local d = true

local Points = script.Parent.Parent.Parent.Points

local NewPoint = 1

local Speed = 10

function GetTime(Distance, Speed)
	local Time = Distance / Speed
	return Time
end

local Train = script.Parent.Parent

Train.PrimaryPart = Train.Center
Train:SetPrimaryPartCFrame(Train.Center.CFrame)

function WeldElevator()
	for i = 1, #Train:GetChildren() do
		if Train:GetChildren()[i] ~= Train.PrimaryPart then
			local Weld = Instance.new("WeldConstraint")
			Weld.Part0 = Train:GetChildren()[i]
			Weld.Part1 = Train.PrimaryPart
			Weld.Parent = Train.PrimaryPart

			Train:GetChildren()[i].Anchored = false
		end
	end
end

script.Parent.ProximityPrompt.Triggered:Connect(function()
	
	if d == true then
		d = false
		
		ts:Create(script.Parent.Parent.Door, TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = script.Parent.Parent.Reference.Position}):Play()
		
		WeldElevator()	
		
		script.Parent.ProximityPrompt.Enabled = false

		wait(3)
		
		script.Event:Fire()
		
		print("ytes")
		
		wait(10)
		
		d = true
		
	end
	
end)
--SERVERSCRIPTSERVICE SCRIPT TO INITILAIZE TWEEN
local NewPoint = 1
local Points = game:GetService("Workspace").Points
local ts = game:GetService("TweenService")
local Train = game:GetService("Workspace").Elevator

local Speed = 10

function GetTime(Distance, Speed)
	local Time = Distance / Speed
	return Time
end

function MoveTrain()
	NewPoint += 1

	local NextPoint = Points["" .. NewPoint]
	local Distance = (Train.PrimaryPart.Position - NextPoint.Position).Magnitude
	local Time = GetTime(Distance, Speed)

	local TweenInformation = TweenInfo.new(
		Time,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out, 
		0,
		false,
		0
	)

	local Tween = ts:Create(Train.PrimaryPart, TweenInformation, {CFrame = NextPoint.CFrame})
	Tween:Play()
	Tween.Completed:Wait() --waits until the tween finished 

end

game:GetService("Workspace").Elevator.SignalEleButton.Script.Event.Event:Connect(function()	
	MoveTrain()
end)

Uh yeah thanks. I really don’t get it why it’s not moving, it may be a WeldConstraint problem.

Thanks

I’d recommend unwelding and rewelding first. Then, retry and read the output bar if it’s not working.

I tried using welds, and then uh the entire thing broke and became a “+”

Photo:

Manual welds don’t work too. I don’t know what the problem is + there’s nothing in the output.

There might be an error, but the script just isn’t reaching it > to single out which parts aren’t working you should put some prints every couple of lines or so. This could help you identify the exact problem making your workflow faster.

Alrighty. I’ll do this and then reach back to this post with more information (if possible)

Hmm…
image

It does tween but doens’t show?

Maybe add a bodyvelocity to the primary part:

local bv = Instance.new("BodyVelocity")
bv.Velocity = Vector3.new(0, 50, 0)
bv.Parent = elevator.PrimaryPart

Then add a part that’s right at the top of the elevator(or the place you want) and name it Elevator end.

elevator.Touched:Connect(function(part)
if part.Name == "ElevatorEnd" then
bv:Destroy()
wait(3)
local bv = Instance.new("BodyVelocity")
bv.Velocity = Vector3.new(0, -50, 0)
bv.Parent = elevator.PrimaryPart

end
end)

Please note that the elevator is a model and you can’t use touched events on models.
image

Oh wait yeah, I’ll fix that soon.

For welds can work fine you need do offset to them like this:

local w = Instance.new("Weld")
w.Part0 = workspace.p1
w.Part1 = workspace.p2
w.C0 = w.Part0.CFrame:Inverse()*w.Part1.CFrame
w.Parent = w.Part0
w.Name = "Parts weld"

Reposting it when I fix the issue.

Maybe add a bodyvelocity to the primary part:

local bv = Instance.new("BodyVelocity")
bv.Velocity = Vector3.new(0, 50, 0)
bv.Parent = elevator.PrimaryPart

Then add a part that’s right at the top of the elevator(or the place you want) and name it Elevator end.
Also make the roof(the top of the elevator) called Roof.

elevator.Roof.Touched:Connect(function(part)
if part.Name == "ElevatorEnd" then
bv:Destroy()
wait(3)
local bv = Instance.new("BodyVelocity")
bv.Velocity = Vector3.new(0, -50, 0)
bv.Parent = elevator.PrimaryPart

end
end)

Much better to just change cframe by bool
I mean here will be bool named “GoingUp” and if its true then just add 1 Y to primary part of model CFrame with checking if its not max and same to go down but without another bool just if “GoingUp” is false then elevator goes down and doing same

Tried this but didn’t work.

THe thing is, I used this mechanic in another elevator too but that worked, I’m recoding it and suddenly nope, it stopped working.

Have you tried my reposted idea yet?

Not yet but I’ll try soon. Thanks for the idea

Problem can be when you doing set parent of weld before putting offsets, it ignores offsets so you need set parent after doing all offsets