Here's a fixed version of your script:
while true do
local newCFrame = CFrame.new(script.Parent.Parent.Torso.CFrame.p + Vector3.new(0, 3.5, 3))
local parentCFrame = script.Parent.CFrame
script.Parent.CFrame = parentCFrame:lerp(NewCFrame, 0.5)
wait(0.5)
end
Here's what I changed:
Firstly, I changed this line of code
local NewCFrame = CFrame.new(script.Parent.Parent.Torso.CFrame.X, script.Parent.Parent.Torso.CFrame.Y + 3.5, script.Parent.Parent.Torso.CFrame.Z + 3)
into this:
local newCFrame = CFrame.new(script.Parent.Parent.Torso.CFrame.p + Vector3.new(0, 3.5, 3))
Rather than creating a CFrame with just raw numbers, you can also create one with a Vector3. So, the new operation does some Vector3 math and then creates a CFrame from the result.
Finally, you had this line of code:
script.Parent.CFrame:lerp(NewCFrame, 0.5)
Which was changed to
script.Parent.CFrame = parentCFrame:lerp(NewCFrame, 0.5)
The reason the old one wasn't working is because lerp is a function of CFrame. Just using lerp doesn't move an object, it returns a CFrame lerped between two CFrames.
That's why you also need to set the CFrame of the object you want to move to what you calculate with lerp.
I hope this helps. Good luck!
1 comment
Thanks :))) (I'm not to good at moving stuff and CFrame. I mostly stick to GUIs and stuff)