Unable to cast Instance to CoordinateFrame

Hello again! i don’t know how to fix my script, it’s an moving laser script with lerping, i tried to use TweenService but i feel lerp smoother and more cooler. Anyways here is the script and the error caused.

local part1 = script.Parent.Part1

local endPart = script.Parent.End

game:GetService("RunService").Heartbeat:Connect(function()

part1.CFrame = part1.CFrame:Lerp(endPart, -0.5 * math.cos(2 * math.pi + 0.5))

end)

image

endPart is an Instance. Use its CFrame property.

part1.CFrame:Lerp(endPart, -0.5 * math.cos(2 * math.pi + 0.5))
-- Should be
part1.CFrame:Lerp(endPart.CFrame, -0.5 * math.cos(2 * math.pi + 0.5))
1 Like

It should be like this
part1.CFrame:Lerp(endPart.CFrame, -0.5 * math.cos(2 * math.pi + 0.5))

Still not working, the lasers won’t move, but no errors are popping out

The lasers won’t move because you set the alpha to a constant -0.5 * math.cos(2 * math.pi + 0.5.
If you want it to move, then you have to use DeltaTime like this:

local startPart = script.Parent.Part1
local endPart = script.Parent.End
local alpha = 0
local speed = 1
local mathConst = -0.5 * math.cos(2 * math.pi + 0.5)

game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
    startPart.CFrame = startPart.CFrame:Lerp(endPart, alpha * mathConst)
    alpha += deltaTime * speed

    if alpha > 1 then
        alpha = 0
    end
end)

I think the “impossible to figure out parts” were necessary in the alpha calculation to stop it from being a linear tween. Maybe show that part of the code?

The script i made is based on Jailbreak Lasers they use kinda like that but i removed some impossible to figure out parts this is the raw code i got, from my friend

  game:GetService("RunService").Heartbeat:Connect(function()
        local v11 = u3.GetNowSync() - p2.BornAtSync
        for i,v in pairs(v6) do
            v13.Part.CFrame = v13.Origin:lerp(v13.Target, -0.5 * math.cos(v11 * (2 * math.pi / v13.Period)) + 0.5)
        end
    end))

the impossible part i mean v13.Period and v13.Origin and v13.Target when i test it, it says Period is not a valid member of v13 ( v13 used to be the laser Part1 )

The script you sen’t won’t work, i want it to Part1 goes to End and Part2 goes to the OtherEnd like on my script but, the Part1 moves to End and it’s stuck there it’s not a loop how it should be