local Trigger = script.Parent
local tree = workspace.FallingTree
local bgs = game:GetService("BadgeService")
local ts = game:GetService("TweenService")
local tinfo = TweenInfo.new(2)
local db = true
Trigger.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
if db == true then
db = false
local tween1 = ts:Create(tree,tinfo,{tree:PivotTo(tree:GetPivot() * CFrame.Angles(0, 0, math.rad(90)))}):Play() -- help here
local tween2 = ts:Create(tree,tinfo,{Position = Vector3.new(517.935, 8.052, -28.476)}):Play()
script.Parent.Sound:Play()
wait(99999)
db = true
end
end
end)
if theres no way, can you tell me the replacement?
This works bcuz the primarypart of a model is the pivot of all of its parts, so when it moves the other descendants of the model move accordingly, with a fixed offset.
FYI: You need to have welds attached to the models descendants
Just to note, the behavior of SetPrimaryPartCFrame() and manually setting the primary part’s CFrame are different. If you don’t have welds connected to the primary part, manually setting the CFrame will not move the other parts with it (this is not the case with SetPrimaryPartCFrame()).
And if you are going to use SetPrimaryPartCFrame(), it’s better to just use PivotTo().
You can lerp a ‘CFrame’ value and pass that as an argument to PivotTo.
local function TweenModel(Model : Model, Duration : number, GoalCFrame : CFrame) : (Model, number, CFrame) -> ()
local Pivot : CFrame = Model:GetPivot()
local Time : number = 0
repeat
Time += task.wait()
local InterpolatedCFrame : CFrame = Pivot:Lerp(GoalCFrame, 1 - ((Duration - Time) / Duration))
Model:PivotTo(InterpolatedCFrame)
until Time > Duration
end
Hey, I’m a bit late but i just fixed the problem with a function.
Here it is:
local tweens = {}
local runService = game:GetService("RunService")
function tweenPivot (object: Model, t: number, newCFrame: CFrame)
if tweens[object] then tweens[object]:Disconnect() tweens[object] = nil end
local startCFrame = object:GetPivot()
local steps = 1 / t
local currentStep = 0
tweens[object] = runService.Stepped:Connect(function(t, dt)
currentStep += steps * dt
if currentStep > 1 then tweens[object]:Disconnect() tweens[object] = nil end
object:PivotTo(startCFrame:Lerp(newCFrame, currentStep))
end)
end
What is basicly does it. It checks for the time you want it to tween. Devides 1 through the time value.
This results in the needed alpha to add to currentStep. Do this times deltaTime (dt) to make sure its frame independed. then you lerp the cframes from current to new times currentStep. and quit once the currentStep is higher then 1.
To prevent multiple tweens from running add the same time its stored in a table under the instance, so when the same instance is requested for tween it will cancel the other one running.