I made a laser that is supposed to spawn and move the direction the player is facing when I press space. Everything else works, except the way the laser is moving.
https://gyazo.com/b13b1c237e3228991c79ac48ef534b93
As you can see, it moves to 0,0,0 for some reason. Why is this? I'm not good with CFrames so sorry if my code is really inefficient!
No errors.
local laser = Instance.new("Part") laser.Parent = workspace.Debris laser.Size = Vector3.new(0.6, 0.767, 3) laser.BrickColor = BrickColor.Red() laser.CFrame = plr.Character.PrimaryPart.CFrame laser.Anchored = true laser.CanCollide = false -- code movement local destination = plr.Character.PrimaryPart.CFrame.lookVector * 3 print(workspace:FindFirstChild(plr.Name).PrimaryPart.CFrame.lookVector) ds:AddItem(laser, bulletSpeed) -- ds is debris service, bulletspeed is 0.7 local tinfo = TweenInfo.new(bulletSpeed, Enum.EasingStyle.Linear, Enum.EasingDirection.Out) local t = ts:Create(laser, tinfo, {Position = destination}) -- ts is tweenservice t:Play() wait(bulletSpeed) t:Cancel()
local destination = plr.Character.PrimaryPart.CFrame.lookVector * 3
This is a vector that describes the orientation of the player's torso as a unit vector, not it's actual position. If you want to offset the player's position by that vector, you'll have to do it explicitly, like so.
local destination = plr.Character.PrimaryPart.CFrame * (plr.Character.PrimaryPart.CFrame.lookVector * 3)