Yes. I do, they are lights, chairs and stuff like that.
Everything must be a part in the model. So you shall ungroup the models in the model if that is possible
I have ungrouped everything and still has an error but instead of model it’s a script. Do I need to put the script outside of the model? Expected BasePart got Script for Weld:Part1.
Edited the code* Also only anchor the primary part in the model.
Okay so here is the fixed code, make sure all parts are unachored, only primary part can be anchored.
local model = script.Parent
local targetPosition = Vector3.new(-290.7, 10.717, 35)
local tweenTime = 10
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local primaryPart = model.PrimaryPart
if primaryPart then
for _,part in pairs(model:GetChildren()) do
if part ~= primaryPart then
if part:IsA('BasePart') then
local weld = Instance.new('WeldConstraint')
weld.Name = part.Name
weld.Parent = primaryPart
weld.Part0 = primaryPart
weld.Part1 = part
end
if part:IsA('Model') then
for _,part2 in pairs(part:GetChildren()) do
local weld = Instance.new('WeldConstraint')
weld.Name = part2.Name
weld.Parent = primaryPart
weld.Part0 = primaryPart
weld.Part1 = part2
end
end
end
end
local tween = TweenService:Create(primaryPart, tweenInfo, {CFrame = CFrame.new(targetPosition)})
tween:Play()
else
warn("No PrimaryPart found in the model. Please set a PrimaryPart for the model.")
end
Is that the code I just send? Because it works in my workplace.
Can you send a screenshot of your model in the explorer?
Maybe tweening isn’t the best solution for what you are trying to do.
You say the model has lights and chairs etc…, what exactly are you trying to tween, and what is the effect you are trying to achieve, in other words why are you tweening it?
Maybe you could simply move the model by cframe with some sort of easing algorithm.
Got the error: Expected BasePart got Model for WeldConstraint:Part1.
How would I do that?
Well, first, what is this model, and what is the effect you want?
Will it need collision or not?
Certain parts have collisions, like the frame and stuff, and some don’t, like the doors and such.
Would I have to move the primary part with like cframe?
Are you tweening a building? Why do you need to tween it?
I’m tweening a train model. Not a building.
You can move an entire model using model:PivotTo(cframe)
The cframe is where you will want to move it to.
I can’t provide any code, so this might be hard to explain.
You determine the ending cframe, call it endCF then you determine the amount of time you want the
model to move to the destination say… duration
Then you need to have a loop, that counts Counter from 0 to duration and gets the position of the cframe with cframe:lerp, or an easing algorighm, by taking the current Counter/duration as the current position in time, and use the PivotTo to place the model at that location.
Sorry if this isnt much help, got a birthday party to take my kid to, or I would type up something.
I need it to move though, not just infinitely teleport.
Have you thought about using a linear velocity to push the train along a track?
No, I don’t even know how to do that.
See if this post has any information that might help you.
I hate to be one of those people, but you should try to search these forums for words like ‘move model along path’ or ‘move train along track’ or even goole those things.
I always hate it when someone tells me to google stuff, as I am notoriously bad at finding anything through search engines, and I also feel a bit offended, like ‘how do they know if I have or have not searched all over creation already’
All that aside though, usually when I take the advice and search for things, I tend to find a lot of good resources and even unexpected gems of code and knowledge. Happy hunting.