What do you want to achieve? Keep it simple and clear!
-I want to rotate a door 90 degrees. I tried to rotate the primary part of the model to rotate all the model.
What is the issue? Include screenshots / videos if possible!
-The function ran, but it just didn’t rotate, no error in the output.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
-I don’t know what the **** is the issue, I stuck here for 2 hours. Please help!
this is the script.
local function test()
local carPrimaryPart = script.Parent.Parent.Primary
local TweenService = game:GetService("TweenService")
local carTweenInfo = TweenInfo.new(
5,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local newCFrame = carPrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0)
local carRotationTween = TweenService:create(carPrimaryPart, carTweenInfo, {CFrame = newCFrame})
carRotationTween:Play()
end
test()
Oh I found the issue, the script DID WORK, but I set the primaryPart invisible so I didn’t see it. But the new issue is that only the primaryPart rotated, the model didn’t. Can you help me?
Well Primary Part Doesnt Rotate a Part. And it will never be this way but you can solve this in two ways.
1.) Loop : Loop through all the Parts and next just play the tween relative to their rotation and position so they tween at the same Form while the model changes its position.
for i,v in Model:GetChildren() do
if v:IsA("BasePart") then
local Tween = game.TweenService:Create(v,
TweenInfo.new(1--[[rest ur stuff)]]),
{["CFrame"] = v.CFrame * CFrame.Angles(0,math.rad(90),0)})
Tween:Play()
end
2.) Physics Based.
Do the Following:
Make Sure that PrimaryPart is Anchored and is Either Near or at the Center of Model AND if it encloses the whole model( second one is not neccesary but it can help you in future if you want to know bounds of your model.). Next Check for any Union or Mesh or Part which has to move in model and add a weld constraint to it.
set Part0 as the PrimaryPart while the Orignal Part to be Part1
Next Make sure that these parts are UNANCHORED.
heres a simple function to do that tedious job for you.
function MakeValidForMovementOrRotation(model)
if not model.PrimaryPart then
return
else
for i,v in model:GetChildren() do
if v:IsA("BasePart") and model.PrimaryPart ~= v then
local WC = Instance.new("WeldConstraint",v)
WC.Part0 = model.PrimaryPart
WC.Part1 = v
v.Anchored = false
elseif v:IsA("UnionOperation") and model.PrimaryPart ~= v then
local WC = Instance.new("WeldConstraint",v)
WC.Part0 = model.PrimaryPart
WC.Part1 = v
v.Anchored = false
elseif model.PrimaryPart == v then
v.Anchored = true
end
end
end)