Issues with model and elevator

Hi all,

I have an issue with my elevator script. I am cloning a model to the elevator, positioning it, welding it, and then moving the elevator. The cloning and positioning work, but the model falls through the floor, apart from it’s primary part. The primary part for the model is “GoesHere”. Also, in the elevator, the part i want the model to attach to is also called “GoesHere”.

Code
module.GenerateItemModel = function(player, plot) --- something aint right
	local randomItem = rarityModule:PickRandomModel(itemFolder)
	if not randomItem then return end
	randomItem.Parent = plot:FindFirstChild("ElevatorItemHolder")
	
	for x, a in ipairs(randomItem:GetChildren()) do
		if a.Name ~= "GoesHere" and a:IsA("BasePart") then
			a.Anchored = true
		end
	end
	
	local rootPartWeld = randomItem.RootPart:FindFirstChild("WeldConstraint")
		or Instance.new("WeldConstraint", randomItem.RootPart)
	rootPartWeld.Part0 = randomItem.RootPart
	rootPartWeld.Part1 = randomItem.FakeRootPart
	
	local goesHereWeld = randomItem.GoesHere:FindFirstChild("WeldConstraint")
		or Instance.new("WeldConstraint", randomItem.GoesHere)
	goesHereWeld.Part0 = randomItem.GoesHere
	goesHereWeld.Part1 = randomItem.RootPart
	
	randomItem:PivotTo(plot.GoesHere.CFrame)

	local weld = Instance.new("WeldConstraint", randomItem.GoesHere)
	weld.Part0 = randomItem.GoesHere
	weld.Part1 = plot.GoesHere

	local hasSent = Instance.new("BoolValue", randomItem)
	hasSent.Name = "HasSent"
	hasSent.Value = false
	
	task.wait()
	
	for x, a in ipairs(randomItem:GetChildren()) do
		if a.Name ~= "GoesHere" and a:IsA("BasePart") then
			a.Anchored = false
		end
	end
end
----- rest of code, irrelevant

I have tried anchoring, unanchoring, welding, motor6ds, can collide, all of that, but the following problems still occur:

  • Model positions properly but falls through the floor
  • Models position properly but doesnt move with the elevator (anchored)
  • Model positions properly AND moves with elevator, but the movement is bouncy and jittery - not smooth

Any ideas? If you require more information, please ask.

1 Like

It looks like you’re not welding the elevator to itself, you need to create a WeldConstraint between every BasePart and the model PrimaryPart.

Oh sorry, i forgot to mention, there is a pre-existing weld between the elevator and the elevator.goeshere

May help
local function GenerateItemModel(player, plot)
	local randomItem = rarityModule:PickRandomModel(itemFolder)
	if not randomItem then return end
	randomItem = randomItem:Clone()
	randomItem.Parent = plot:FindFirstChild("ElevatorItemHolder")

	for _, a in ipairs(randomItem:GetDescendants()) do
		if a:IsA("WeldConstraint") or a:IsA("Motor6D") then
			a:Destroy()
		end
		if a:IsA("BasePart") then
			a.Anchored = true
		end
	end

	randomItem:PivotTo(plot.GoesHere.CFrame)

	for _, a in ipairs(randomItem:GetChildren()) do
		if a:IsA("BasePart") and a ~= randomItem.RootPart then
			local w = Instance.new("WeldConstraint")
			w.Part0 = randomItem.RootPart
			w.Part1 = a
			w.Parent = randomItem.RootPart
		end
	end

	local w = Instance.new("WeldConstraint")
	w.Part0 = randomItem.RootPart
	w.Part1 = plot.GoesHere
	w.Parent = randomItem.RootPart

	local hasSent = Instance.new("BoolValue")
	hasSent.Name = "HasSent"
	hasSent.Parent = randomItem

	task.wait()

	for _, a in ipairs(randomItem:GetChildren()) do
		if a:IsA("BasePart") then
			a.Anchored = false
		end
	end
end

return {GenerateItemModel = GenerateItemModel}

Trying to stick with your set up.

ElevatorPreset.rbxl (66.2 KB)
One of my presets..
A Lift and a Elevator.

That fixes the problem! Thank you.

I’m now facing an issue where the model positions itself just above “GoesHere”. Unsure why. I checked and Model.GoesHere positions properly, but the rest of the model kinda hovers above it, i think due to the new welding system.

ModuleScript
--ModuleScript in ReplicatedStorage
module.GenerateItemModel = function(player, plot)
	local randomItem = rarityModule:PickRandomModel(itemFolder)
	if not randomItem then return end
	randomItem.Parent = plot:FindFirstChild("ElevatorItemHolder")
	
	for _, part in ipairs(randomItem:GetChildren()) do
		if part:IsA("BasePart") and part.Name ~= "GoesHere" then
			part.Anchored = true
		end
	end
	
	randomItem:PivotTo(plot.GoesHere.CFrame)
	
	for _, part in ipairs(randomItem:GetChildren()) do
		if part:IsA("BasePart") and part.Name ~= "GoesHere" then
			local weld = Instance.new("WeldConstraint")
			weld.Part0 = randomItem.GoesHere
			weld.Part1 = part
			weld.Parent = part
			part.Anchored = false
		end
	end
	
	local mainWeld = Instance.new("WeldConstraint")
	mainWeld.Part0 = plot.GoesHere
	mainWeld.Part1 = randomItem.GoesHere
	mainWeld.Parent = randomItem.GoesHere
	
	local hasSent = Instance.new("BoolValue", randomItem)
	hasSent.Name = "HasSent"
	hasSent.Value = false
end
ModuleScript, different approach
--ModuleScript in ReplicatedStorage
module.GenerateItemModel = function(player, plot)
	local randomItem = rarityModule:PickRandomModel(itemFolder)
	if not randomItem then return end
	randomItem.Parent = plot:FindFirstChild("ElevatorItemHolder")

	local primary = randomItem:FindFirstChild("GoesHere")
	if not primary then return end

	for _, part in ipairs(randomItem:GetDescendants()) do
		if part:IsA("BasePart") and part ~= primary then
			part.Anchored = true
		end
	end

	randomItem:PivotTo(plot.GoesHere.CFrame)

	for _, part in ipairs(randomItem:GetDescendants()) do
		if part:IsA("BasePart") and part ~= primary then
			local weld = Instance.new("WeldConstraint")
			weld.Part0 = primary
			weld.Part1 = part
			weld.Parent = part
			part.Anchored = false
		end
	end

	local mainWeld = Instance.new("WeldConstraint")
	mainWeld.Part0 = plot.GoesHere
	mainWeld.Part1 = primary
	mainWeld.Parent = primary

	local hasSent = Instance.new("BoolValue", randomItem)
	hasSent.Name = "HasSent"
	hasSent.Value = false
end

I struggled with getting this right myself in terms of smoothness.
I have quite a few attempts at it. That second one is like a fail-safe.
All the parts need to be welded to the primary part, not mixed matched.
This was such a hassle that I made a preset for it..

That preset is just the raw parts, So the magic parts :rofl: are there.

Thank you for making these scripts, but it doesn’t quite work. The model still hovers over “goeshere”

These really depend on how you have them set up. My scripts end up being guesses for something like this. That’s why I gave you that preset. The part that does the moving is all self contained. So you may want to stick with that. Be careful how you move them because even that can break it. You could do up and down or side to side with that model set up. You could make the pad smaller and transparent, then weld it to your floor part. Or maybe use your floor part after you line that up.
At least take a good look at it, that took many tries to get to be a stand alone like that.

I don’t think it’s the elevator’s problem, but the model being welded/positioned weirdly.

Helps if that is all welded to the same part.. the moving part.