Create some Laser Eyes

Hello this is my first tutorial but in this tutorial I will be showing you how to make Laser Eyes

Setting it up

Screen Shot 2021-04-05 at 4.22.36 PM
We are going to start by making a Tool in starter pack, add a server script, local script, and remote event, you could name it whatever you want(Make sure it has require handle off).
Then we are going to add a part/meshpart in server storage but I am going to be using a mesh part I made with this tutorial: VFX Tutorial | ROBLOX


Next put it in server storage and I am going to be naming it LaserPart(Make sure it is anchored and can collide off).
Screen Shot 2021-04-05 at 4.16.18 PM

Scripting the Laser

local Tool = script.Parent
local player = game.Players.LocalPlayer
--local Mouse = player:GetMouse()
local UserInputService = game:GetService("UserInputService")
local Event = Tool:WaitForChild("RemoteEvent")
local RunService = game:GetService("RunService")
local Equipped = false
local camera = workspace.CurrentCamera

Tool.Equipped:Connect(function()
	Equipped = true
end)

Tool.Activated:Connect(function()
	RunService.Heartbeat:Connect(function()
		if Equipped then
			local mouse = UserInputService:GetMouseLocation()
			local unitray = camera:ScreenPointToRay(mouse.X , mouse.Y)
			Event:FireServer(unitray)
			end
		wait()
	end)
end)

Tool.Unequipped:Connect(function()
	Equipped = false
end)

We will use heartbeat to fire the event every Frame on the local script and use the wait just in case it causes lots of lag, and use the equip variable so it won’t fire the event when the tool is equipped(We are using unitary since for some reason using mouse hit p would make the part go up if anyone knows why could you tell me).

local Tool = script.Parent
local Event = Tool:WaitForChild("RemoteEvent")
local Switch = true
local Equipped = false
local Length = 500
local Damage = 24
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
local Debris = game:GetService("Debris")

Tool.Equipped:Connect(function()
	Equipped = true
end)

local Folder = Instance.new("Folder", workspace)
Folder.Name = "LaserParts"

local function CFramePointRightSide(Pos1 ,HitPosition) -- Use this if you are using a cylinder and for the size change the x axis and for the cframe
	local directionToFace = (Pos1 - HitPosition).unit
	local worldUp = Vector3.new(0,1,0)
	local zAxisFace = directionToFace:Cross(worldUp)
	local yAxisFace = directionToFace:Cross(zAxisFace)
	return CFrame.fromMatrix(Pos1, directionToFace, yAxisFace, -zAxisFace)
end


Tool.Activated:Connect(function()
if Switch then
	Switch = false
	Beam = game.ServerStorage:WaitForChild("LaserPart"):Clone()
	Beam.Parent = Folder
Event.OnServerEvent:Connect(function(player, unitray)
	if Equipped and not Switch then
		local character = player.Character 
			local Humanoid = character:WaitForChild("Humanoid")
			if Humanoid and Humanoid:GetState() ~= Enum.HumanoidStateType.Dead and character:WaitForChild("HumanoidRootPart") then
			local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
			local Head = character:WaitForChild("Head")
			rayParams.FilterDescendantsInstances = {Beam, character, Folder}	
			local origin = Head.CFrame.Position	
			local direction = unitray.Direction * Length--(MouseHit - origin).Unit * Length	
			local LaserRay 	= workspace:Raycast(origin, direction, rayParams)
			if LaserRay then
			else
			LaserRay = {}
				LaserRay.Position = origin + direction	
				end	
				local Distance = (origin - LaserRay.Position).Magnitude	
				Beam.Size = Vector3.new(1,1,Distance)
				Beam.CFrame = CFrame.lookAt(origin, LaserRay.Position) * CFrame.new(0,0, -Distance/2) 
				if LaserRay and LaserRay.Instance then
					local object = LaserRay.Instance
						if object.Parent:FindFirstChildWhichIsA("Humanoid") then
						local Enemy = object.Parent:FindFirstChildWhichIsA("Humanoid")
					Enemy:TakeDamage(Damage)
				end	
			end	
					
		end
	end
	wait()		
end)
	elseif not Switch then
		Switch = true
		Debris:AddItem(Beam, .01)
	end
end)

Tool.Unequipped:Connect(function()
	Equipped = false
	Debris:AddItem(Beam, .01)
end)

Lastly, we have to make the server script work we start with some variables to and make a click variable to turn off and on the laser. We clone the laser part before the event is fired then we get the character and make a ray, and we could now cframe and change the size of the laser part by the laser position.We then get the part that was hit and find a humanoid and damage then. Finallyyy we are done! Hopefully you liked this tutorial since it was my first one.

19 Likes

“Why would I need laser in my eyes?”

Great explanition, I understood all the thing but you would use some particles. Like when laser touches the wall it would give an effect. You would give a bit more details over this.

1 Like

The tool doesn’t work and idk why. Please i need this for an upcoming game.

If you do not have a hand turn of requires handle on the properties of the tool.

Thanks man, I was making a superman game. This is one of the many things i needed.

By the way I might be making another tutorial or just a resource with pre-made laser eyes if you are willing to support one of the ideas.

I’m ok with anything… But i think you should add the fact you should turn off RequiresHandle in the tutorial just in case people cant figure it out.

Hi again, i wonder how i could implement a limited duration for the laser eyes. I dont want them to be op… I also need it to not be a tool and it needs to have a cooldown too. Thats a problem for me… Is there a way to make those possible?

If you would like I will make a tutorial like later today about using a cool down and without a tool.

Yess thank you! Some people would love to have the Laser Eyes ability fully intergrated in the game. Not as a tool.

Is this what you are looking for? I made this test and I will make a tutorial on it later, but I just want to know if this is good.;

Yes this is exactly how i want it to be… Wow, You did so well on this thing. Def wanna learn via the tutorial. So Long story short, This is amazing and how i wanted it to be. Also cant wait for the tutorial.

Here I made the new tutorial I hope you like it and anyone else will enjoy it as well and use it!!;