I have made a part that spawns in front of the player while they hold Z, and the only way I got it to stay there was when I made it anchored, though I want to make it stay in front of the player while the player moves.
while KeyHeld == true do power.CFrame = player.Character.Head.CFrame*CFrame.new(Vector3.new(0, 5, -1.5)) end
But all it does is sit in the middle of the map. Before I used the while loop I just had it anchored so that's the only way I got it to go in front of the player when the button is pressed, but when I use the while loop, having it anchored or not anchored doesn't make much of a difference.
Actually, in my opinion, there is a better way of doing this than using a loop: welds. By using welds, you have no use for a loop and it will not seem choppy, but rather smooth.
It is actually fairly simple as well:
-- Example welding of a part with a 5 stud offset from another part function weld(part1, part2) local weld = Instance.new("Weld", part1) weld.Part0 = part1 weld.Part1 = part2 weld.C0 = CFrame.new(0, 0, 5) end
With the example given above, you should be able to easily figure out how to implement it for your purposes.
Make sure to accept my answer if it helped! :)
Try:
local Char = player.Character or player.CharacterAdded:Wait() while KeyHeld do wait() print('Looping') print(Power.CFrame) power.CFrame = CFrame.new(Char:WaitForChild('Head').Position)*CFrame.new(0,0,-5) print(Power.CFrame) end
Hopefully this helped
If it doesn't work open up Output or press F9 and tell me if there is error