I want to make it so that the part teleports in front of my sword whenever I press C, but it only does that whenever I’m looking at a certain place, and not all the time. Here’s my code and video displaying the problem:
local dffd = workspace.dffd -- part
local sword = workspace.heavenswilI.ClassicSword.Handle
game:GetService("UserInputService").InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.C then
dffd.CFrame = CFrame.new(0,0,-5) * sword.CFrame
end end)
local dffd = workspace.dffd
local sword = workspace.heavenswilI.ClassicSword.Handle
game:GetService("UserInputService").InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.C then
dffd.CFrame = sword.CFrame:ToObjectSpace()
end end)```
I’m pretty sure these two have the exact same effect, but I thought the second one would be better for performance since it’s not generating a second CFrame.
Turns out that the CFrame multiplier is actually better for performance: