If the knife is only a visual effect, you should use RunService.RenderStepped, and only if the knife is actually on the screen.
Here’s a sample script you can place inside a random part in workspace to see work.
local part = script.Parent
local rotateSpeed = 3 -- the speed the part rotates (in rotations per second)
local tau = (2 * math.pi)
local rotation = (tau * rotateSpeed)
local RunService = game:GetService("RunService")
-- Anchor the part if it isn't already anchored
part.Anchored = true
-- Run our loop
RunService.Heartbeat:Connect(function(deltaTime: number) -- you should use RenderStepped instead of Heartbeat
part.CFrame *= CFrame.Angles(0, 0, (rotation * deltaTime))
end)
Anyway, just create a new part and plop this script inside and you’re good to go.
This isn’t actually meant to solve your problem, I’m just providing sample code to show how you can make the knife rotate.
Oh. Just re-read your post. You can accomplish this using CFrame.lookAt
local knifePos = knifeClone:GetPivot().Position
knifeClone:PivotTo(CFrame.lookAt(knifePos, knifePos + Character:GetPivot().LookVector))
This will only make the knife look in the direction the torso is facing. If you want it to look in the direction the head is looking in you can use Character.Head:GetPivot().Position instead.
Also, you may have to rotate the lookAt CFrame by 90 or 180 degrees on one of it’s axis, depending on which face of the knife you want looking in the direction the character is looking.
In this case it probably only needs to be rotated by 90 degrees on one axis, at least from what I saw.
local correctionRotation = CFrame.Angles(0,0(math.pi * 0.5)) -- math.pi/2 is 90 degrees
local knifePos = knifeClone:GetPivot().Position
local knifeFrame = CFrame.lookAt(knifePos, knifePos + Character:GetPivot().LookVector) * correctionRotation
knifeClone:PivotTo(knifeFrame)
You may have to change the axis (math.pi * 0.5) is on in the CFrame.Angles variable, but you should be able to get it with some experimentation. You may also need to negate (math.pi * 0.5) to get the result you’re looking for.
Sorry to tell you but it still didn’t work. I tried experimenting but it still didn’t work. Maybe we could somehow get the direction the character is looking at and send the knife to that direction? Just saying. P.s I’m not good with rotating so I might not under some stuff you say.
sorry for the late reply but its hard to tell if your code using position which im asuming it does so here.
knifeClone.CFrame = Character.HumanoidRootPartCFrame*CFrame.new(0,0,-1)*CFrame.Angles(math.rad(-90),math.rad(-90),0) -- teleports to the players rootparts coordinates moves it infront one stud and changes angles accordingly.
knifeClone.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-1)*CFrame.Angles(math.rad(-90),math.rad(-90),0) -- teleports to the players rootparts coordinates moves it infront one stud and changes angles accordingly.
knifeClone.CFrame = Character.HumanoidRootPartCFrame*CFrame.new(0,0,-1)*CFrame.Angles(math.rad(-90),math.rad(90),0) -- teleports to the players rootparts coordinates moves it infront one stud and changes angles accordingly.