Hey devs,
I have an issue tweening a model.
This is my code:
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
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
It gives me the warning No PrimaryPart found in the model. Please set a PrimaryPart for the model.
Thank you.
You need to set the primary part in the properties.
1 Like
I set it, and it worked, there’s no errors.
But now the issue is… the model won’t tween.
Try welding the parts in the model to the primary part.
1 Like
How can I do that? There’s like a thousand parts in the model.
There is a plugin where you can just shift select the parts and press weld on the plugin.
Make sure that the first selected part is the primary part though.
1 Like
Can I weld the whole model? char
You can also make a weld script that welds all the parts in the model to the primary part.
1 Like
How? Can you give me a sample of the code? @BlurBaviaan
This will probably do it.
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
for _,part in pairs(model:GetChildren()) do
if part ~= primaryPart then
local weld = Instance.new('Weld')
weld.Name = part.Name
weld.Parent = primaryPart
weld.Part0 = primaryPart
weld.Part1 = part
end
end
if primaryPart then
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
1 Like
Do you have models in your model that you want to move?
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
1 Like
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
1 Like
Is that the code I just send? Because it works in my workplace.
Can you send a screenshot of your model in the explorer?