Clone not going in the right place

I am making a uni beam and I want the beam in front of the player no matter what way they are facing. I have tried just increasing the X position but that changes based on what way they are facing.

What Happens:

What I want to happen:
image

Code:

local Player = game:GetService("Players").LocalPlayer
local Controls = require(Player.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.E then
		print("Pressed E!")
		local UniBeam = ReplicatedStorage.Magic.UniBeam.Main:Clone()
		UniBeam.Parent = Player.Character
		UniBeam.CFrame = Player.Character.HumanoidRootPart.CFrame
		UniBeam.Orientation = Vector3.new(UniBeam.Orientation.X, (UniBeam.Orientation.Y + 90), UniBeam.Orientation.Z)
		--UniBeam.Position = Vector3.new((UniBeam.Position.X + (UniBeam.Size.X / 2)), UniBeam.Position.Y, UniBeam.Position.Z)
		--Controls:Disable()
	end
end)
local Player = game:GetService("Players").LocalPlayer
local Controls = require(Player.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local angle = CFrame.Angles(0, math.rad(90), 0)
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.E then
		print("Pressed E!")
		local UniBeam = ReplicatedStorage.Magic.UniBeam.Main:Clone()
		UniBeam.Parent = Player.Character
		UniBeam.CFrame = Player.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, UniBeam.Size.Z * -.5) * angle
	end
end)

I tried your code and the same thing happened

Edit: I need the beam in front of the player also

try X size instead of Z

CFrame.new(0, 0, UniBeam.Size.X * -.5)
1 Like