Hello, currently making a sushi conveyor belt but am struggling to get the model’s parts to be welded and then tweened. I want the food models to be easily added by the client, so am trying to make a weld script, rather than the client having to add the welds themselves.
What do you want to achieve? I want each of the parts in the model to be welded to the primary part of the model, and then when that model is tweened, the welded parts all move along with the model.
What is the issue? From the picture below, you can see that the primary parts of the models are being moved along nicely, but the welded parts are staying put. I have shown the weld constraints (the green lines).
What solutions have you tried so far? I have searched all over the developer forum trying to find a solution, but nothing seems to be working. I have tried using a Weld rather than Weld Constraint and then setting the C1 and C0, but that didn’t turn out right either as the welded parts did not stay in their relative positions, they ended up being welded in strange positions as you can see below (not how they are modelled):
-- Function to weld all parts within a model
local function createWelds(Model)
if Model.PrimaryPart ~= nil then
Model.PrimaryPart.Anchored = true
for _, Part in pairs(Model:GetDescendants()) do
if Part:IsA("BasePart") and not (Model.PrimaryPart == Part) then
local Weld = Instance.new("WeldConstraint", Model.PrimaryPart)
Weld.Part0 = Part
Weld.Part1 = Model.PrimaryPart
Part.Anchored = false
end
end
end
end
-- Function to move a food model to the next waypoint
local function moveToNextWaypoint(foodModel)
local currentIndex = foodModel:GetAttribute("WaypointIndex")
local nextIndex = currentIndex + 1
if nextIndex <= #waypoints then
local nextWaypoint = conveyorWaypoints["Waypoint"..tostring(nextIndex)]
foodModel:SetAttribute("WaypointIndex", nextIndex)
local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local newPos = nextWaypoint.Position
local part = foodModel.PrimaryPart or foodModel
local Tween = TweenService:Create(part, tweenInfo, {Position = newPos})
Tween:Play()
Tween.Completed:Wait()
if foodModel.Parent then
moveToNextWaypoint(foodModel)
end
else
foodModel:Destroy()
end
end
I had a similar thing with rotating tweening a model recently. You could either try Unioning the thing instead of modelling it, or moving each individual part.
Unioning wouldn’t be good since the model has separate textures and mesh IDs for each part.
Also tweening each individual part would not be very efficient and I think is not very necessary since it’s something to do with the welding I think is not working properly.
Instead of tweening the position, you should try tweening the CFrame. So {[“CFrame”] = CFrame.new(newPosition)}. Weld Constraints weld for CFrames as far as I’m aware, changing position itself is the same as changing the offset of a part for a Weld.
That has worked to an extent. The model now moves together as one, however I am still experiencing the issue whereby the positioning of the parts are not relative to their original position. They are off-centered / out of position when they should be just as the food model is already. Do you know how I would go about correcting this?
Thanks for your response. I did in fact check out that article previously, but nothing seemed to help. And to be clear, I thought the issue was to do with welding - which I am pretty sure it still is, so you would not be incorrect in saying that (unless I am mistaken). Thank you for the other notes, will take those on board also.
I think I see your problem. When you use the create welds function, I’m assuming the parts are offset for some reason. You should manually try welding them, then use :Clone() on the already welded one to see if that is the issue. Otherwise, I’m assuming the issue is somewhere before the code you provided.