This script is inside a click detector inside a model. But it is not working. It is anchored so parts wont fall out of the model. Im not sure if this should be in a local script or a regular one either.
local Model = Workspace.Model local newPos = Model.Position + Vector3.new(0,5,0) local Time = 10 local Increment = 0.5 local Debounce = false local Diff = newPos - Model.Position local Mag = Diff.magnitude local Direction = CFrame.new(Model.Position, newPos).lookVector function MovePart() if Debounce then return end Debounce = true for n = 0, Mag, Increment do Model.CFrame = Model.CFrame + (Direction * Increment) wait( (Time/Mag) * Increment ) end Debounce = false end Workspace.Button.ClickDetector.MouseClick:connect(MoveModel)
Models don't have a CFrame property, only Parts and Unions do. Try setting the Model's PrimaryPart
property, and using the SetPrimaryPartCFrame
function:
local Model = Workspace.Model local newPos = Model.PrimaryPart.Position + Vector3.new(0,5,0) local Time = 10 local Increment = 0.5 local Debounce = false local Diff = newPos - Model.PrimaryPart.Position local Mag = Diff.magnitude local Direction = CFrame.new(Model.PrimaryPart.Position, newPos).lookVector function MoveModel() if Debounce then return end Debounce = true for n = 0, Mag, Increment do Model:SetPrimaryPartCFrame(Model.PrimaryPart.CFrame + (Direction * Increment)) wait( (Time/Mag) * Increment ) end Debounce = false end Workspace.Button.ClickDetector.MouseClick:connect(MoveModel) --You changed this to `MoveModel` without changing the name of the function. I fixed this for you.
local Model = Workspace.Model -- Assuming this is a BasePart local newPos = Model.Position + Vector3.new(0,5,0) local Time = 10 local Increment = 0.5 local Debounce = false local Diff = newPos - Model.Position local Mag = Diff.magnitude local Direction = CFrame.new(Model.Position, newPos).lookVector function MovePart() if Debounce then return end Debounce = true for n = 0, Mag, Increment do Model.CFrame = Model.CFrame * CFrame.new(Direction * Increment) --Changed here, CFrame can be a little funny about addition of Vector3 wait( (Time/Mag) * Increment ) end Debounce = false end Workspace.Button.ClickDetector.MouseClick:connect(MoveModel)