Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
jqrx 0
8 years ago

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

Log in to vote
-2
Answered by 8 years ago

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!

0
r_arm.CFrame = r_arm.CFrame:lerp(...) is already correct, a new variable wasn't necessary. 1waffle1 2908 — 8y
0
@1waffle1 Style preference. I like using a variable for such things. Programmix 285 — 8y
Ad

Answer this question