Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't my "CFrame:lerp" script work?

I've been trying to make this work. Why doesn't it?

char = game.Players.LocalPlayer.Character
r_arm = char["Right Arm"]
head = char["Head"]
r_arm.Anchored = false

while wait() do
	r_arm.CFrame = r_arm.CFrame:lerp(head.Position,0.90)
end

Help would be appreciated.

1 answer

Here's a fixed version of your script:

local char = game.Players.LocalPlayer.Character
local r_arm = char["Right Arm"]
local head = char["Head"]
r_arm.Anchored = false

while wait() do
    local r_armCFrame = r_arm.CFrame:lerp(head.CFrame,0.90)
    r_arm.CFrame = r_armCFrame
end

Here's what I changed:

First, I added the local keyword to all of your variables. local variables have many benefits and should always be used when possible.

You had this line of code:

r_arm.CFrame = r_arm.CFrame:lerp(head.Position,0.90)

Which was changed to

local r_armCFrame = r_arm.CFrame:lerp(head.CFrame,0.90)
r_arm.CFrame = r_armCFrame

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!

2 comments

0

r_arm.CFrame = r_arm.CFrame:lerp(...) is already correct, a new variable wasn't necessary.

0

@1waffle1 Style preference. I like using a variable for such things.

This discussion is preserved as it was. New answers, comments, and votes are closed.