Help with lazer eyes

I need help tweening the lazer eyes to the target but it doesn’t really work.

local function tweenLazerEyes(leftDirection, rightDirection)
	local leftLazerEyeBone = RootPart.BottomBone.UpperBone.HeadBone.LeftLazerEyeBone
	local rightLazerEyeBone = RootPart.BottomBone.UpperBone.HeadBone.RightLazerEyeBone

	local leftStartPosition = leftLazerEyeBone.WorldPosition
	local rightStartPosition = rightLazerEyeBone.WorldPosition

	local leftLazer = ReplicatedStorage:WaitForChild("Lazer"):Clone()
	local rightLazer = ReplicatedStorage:WaitForChild("Lazer"):Clone()
	
	leftLazer.Size = Vector3.new(leftLazer.Size.X, leftLazer.Size.Y, 0)
	rightLazer.Size = Vector3.new(rightLazer.Size.X, rightLazer.Size.Y, 0)
	
	leftLazer.CFrame = leftLazerEyeBone.WorldCFrame
	rightLazer.CFrame = rightLazerEyeBone.WorldCFrame
	
	leftLazer.Parent = Visuals -- folder
	rightLazer.Parent = Visuals
	
	local leftCenter = leftLazer.Position + leftDirection / 2
	local leftDistance = leftDirection.Magnitude

	local rightCenter = rightLazer.Position + rightDirection / 2
	local rightDistance = rightDirection.Magnitude

	local leftSizeTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
	local leftSizeTween = TweenService:Create(leftLazer, leftSizeTweenInfo, {Size = Vector3.new(leftLazer.Size.X, leftLazer.Size.Y, leftDistance)})
	leftSizeTween:Play()

	local leftCFrameTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
	local leftCframeTween = TweenService:Create(leftLazer, leftCFrameTweenInfo, {CFrame = CFrame.new(leftCenter, leftStartPosition)})
	leftCframeTween:Play()
end

local raycastLazerEyesMaxRange = 1000

local function raycastLazerEyes(target) -- target is a basepart
	local leftLazerEyeBone = RootPart.BottomBone.UpperBone.HeadBone.LeftLazerEyeBone
	local rightLazerEyeBone = RootPart.BottomBone.UpperBone.HeadBone.RightLazerEyeBone

	local leftRayOrigin = leftLazerEyeBone.WorldPosition
	local rightRayOrigin = rightLazerEyeBone.WorldPosition

	local leftDirection = (target.Position - leftRayOrigin).Unit * raycastLazerEyesMaxRange
	local rightDirection = (target.Position - rightRayOrigin).Unit * raycastLazerEyesMaxRange
	tweenLazerEyes(leftDirection, rightDirection)
end

Result:


I can’t figure out how to fix this.

2 Likes

Maybe you can make an loop using Coroutine.Wrap()
then using “Resize()”

example:

coroutine.wrap(function()
	while task.wait() do
		script.Parent:Resize(Enum.NormalId.Left,1)
	end
end)()

coroutine wrap doens’t stop your whole script, so thats why i recommend it
Resize() will add more size to selected face of a part

so the loop gonna add +1 size every milisecond to the left side

(that my first time replying a post on this forum, so i hope i can help.)

Thats not the problem, the problem is the cframe.

Why you are tweening the CFrame?

Because if you only tween the size, the lazer would go through the head.

thats why i recommend using Resize() instead of tweens, because it only add more size to an face of the cylinder and not to the two, but for that you would do a loop

1 Like

Yes but that wouldn’t be smooth.

then use RunService Heartbeat

Yes but I want to use TweenService.

Current Code:

local leftStartPosition = leftLazerEyeBone.WorldPosition

	local leftLazer = ReplicatedStorage:WaitForChild("G-ManLazer"):Clone()

	leftLazer.Size = Vector3.new(leftLazer.Size.X, leftLazer.Size.Y, 0)

	leftLazer.CFrame = leftLazerEyeBone.WorldCFrame

	local leftCenter = leftLazer.Position + leftDirection / 2
	local leftDistance = leftDirection.Magnitude

	leftLazer.CFrame = leftLazerEyeBone.WorldCFrame
	
	local tweenLeftLazerEyesData = {
		Size = Vector3.new(leftLazer.Size.X, leftLazer.Size.Y, leftDistance),
		CFrame = CFrame.new(leftCenter, leftStartPosition),
	}