Laser Eye script not working

as the title says, i’m making a laser eye script for a game. For some reason I made it in a local script first cause its a habit I have sometimes. I decided to convert it to the server and It wont work at all. Nothing is being printed to the console.

Heres my script. If anyone has any ideas of what I did wrong please tell me. Thanks in advance!
SERVER:

game.ReplicatedStorage.Remotes.Lasere.OnServerEvent:Connect(function(player,modell,mouse)
	local AudioModule = require(game.ReplicatedStorage.AudioModule)
	local GroundEFF = require(game.ReplicatedStorage.GroundEffect)
	local AnimModule = require(game.ReplicatedStorage.AnimationModule)
	local Oof = require(game.ReplicatedStorage.hi)
	local char = player.Character
	local hrp = char.HumanoidRootPart
	local thing = Instance.new("Part",modell)
	thing.CanCollide = false
	thing.CFrame = hrp.CFrame * CFrame.new(0,2,5)
	thing.Anchored = true
	thing.BrickColor = BrickColor.new("Yellow flip/flop")
	thing.Material = "Neon"
	print("oh")
	local s = Instance.new("Part",workspace)
	s.CanCollide = false
	s.CFrame = char.Head.CFrame * CFrame.new(0.2,0.4,0)
	s.Anchored = true
	s.Transparency = 1
	s.Size = Vector3.new(1,1,1)

	local f = Instance.new("Part",modell)
	f.CanCollide = false
	f.CFrame = CFrame.new(mouse)
	f.Anchored = true
	f.Transparency = 1
	f.Name = "What"
	f.Size = Vector3.new(1,1,1)
	local thing2 = Instance.new("Part",modell)
	thing2.CanCollide = false
	thing2.CFrame = hrp.CFrame * CFrame.new(0,2,5)
	thing2.Anchored = true
	thing2.BrickColor = BrickColor.new("Yellow flip/flop")
	thing2.Material = "Neon"
	local s2 = Instance.new("Part",workspace)
	s2.CanCollide = false
	s2.CFrame = char.Head.CFrame * CFrame.new(-1,0.4,0)
	s2.Anchored = true
	s2.Transparency = 1
	s2.Size = Vector3.new(1,1,1)
	local f2 = Instance.new("Part",modell)
	f2.CanCollide = false
	f2.CFrame = CFrame.new(mouse)
	f2.Anchored = true
	f2.Transparency = 1
	f2.Size = Vector3.new(1,1,1)
	local att = Instance.new("Attachment",f)
	local particle = game.ReplicatedStorage.laserparticle:Clone()
	particle.Parent = att
	local deb = false
	coroutine.resume(coroutine.create(function()
		while true do
			f.CFrame = CFrame.new(mouse.X,mouse.Y,mouse.Z)
			f2.CFrame = CFrame.new(mouse.X,mouse.Y,mouse.Z)
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {char}
			raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
			--[[	local ray = Ray.new(s.Position, f.Position - s.Position)
				local ray2 = Ray.new(s2.Position, f2.Position - s2.Position)
				
				local midpoint = ray.Origin + ray.Direction/2
				local midpoint2 = ray2.Origin + ray2.Direction/2 --]]

			local rayhit = workspace:Raycast(s.Position,(f.Position - s.Position) * 1000,raycastParams)
			local rayhit2 = workspace:Raycast(s2.Position,(f2.Position - s2.Position) * 1000,raycastParams)
			local distance = (rayhit.Position - s.Position).Magnitude
			local direction = (rayhit.Position - s.Position)
			local distance2 = (rayhit2.Position - s2.Position).Magnitude
			local direction2 = (rayhit2.Position - s2.Position)
			local MiddlePoint = s.Position + direction/2
			local MiddlePoint2 = s2.Position + direction2/2
			thing.CFrame =  CFrame.new(MiddlePoint,rayhit.Position)
			thing.Size = Vector3.new(0.1, 0.1, distance)
			thing2.CFrame =  CFrame.new(MiddlePoint2,rayhit2.Position)
			thing2.Size = Vector3.new(0.1, 0.1, distance2)
			if rayhit then
				local hit = rayhit.Instance
				if hit.Parent:FindFirstChild("Humanoid") then
					deb = true
					local hum = hit.Parent:FindFirstChild("Humanoid")
					hum:TakeDamage(0.2)
					coroutine.resume(coroutine.create(function()
						wait(0.1)
						deb = false
					end))
				end
			end
			wait()
		end
	end))
	end)

CLIENT:

local modell = Instance.new("Model",workspace)
		mouse.TargetFilter = modell
		game.ReplicatedStorage.Remotes.Lasere:FireServer(modell,mouse.Hit.Position)
1 Like

From the client code you pasted, it looks like your RemoteEvent will be running only one time since it isn’t inside a callable function or a loop, and since this script runs the moment the player is added to the game, the mouse most likely isn’t going to have a hit position since it might not be loaded, or other parts of your game (like the laser eyes) might not be loaded.

I would suggest sticking the remote event inside a .Activated event if it’s a tool instance, or using UserInputService to detect when a certain key is pressed, or the Mouse is clicked.

1 Like

oh I have the code activating when I press the letter “T” on my keyboard. It does damage but for some reason the visual ray doesnt show up.