I took the RobloxDev Forums Raycasting for the Laser gun and just added a cylinder mesh. Is there any way to have the cylinder in the part face the character's torso's lookVector, because I tried LookVector, and it didn't work. All that happens is that the cylinder goes to where the mouse is, but it's rotated weirdly. Eventually, I'll add a bodygyro to have the player face where the mouse is, so that may help.

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local char = workspace:WaitForChild(player.Name)

tool.Equipped:connect(function(mouse)
	print("Tool equipped!")
 
	mouse.Button1Down:connect(function()
		print("Mouse pressed!")
		local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
		local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
 
		local beam = Instance.new("Part", workspace)
		beam.BrickColor = BrickColor.new("Bright red")
		beam.FormFactor = "Custom"
		beam.Material = "Neon"
		beam.Transparency = 0.25
		beam.Anchored = true
		beam.Locked = true
		beam.CanCollide = false
 		local mesh = Instance.new("SpecialMesh")
		mesh.Parent = beam
		mesh.MeshType = "Cylinder"
		
		local distance = (tool.Handle.CFrame.p - position).magnitude
		beam.Size = Vector3.new(25,5, distance)
		beam.Orientation = char.Torso.Orientation
		mesh.Scale = Vector3.new(25,5,distance)
		beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
 
		
 
		if part then
			local humanoid = part.Parent:FindFirstChild("Humanoid")
 
			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end
 
			if humanoid then
				humanoid:TakeDamage(30)
			end
		end
	end)
end)

2 comments

0

https://scriptinghelpers.org/guides/the-first-person-element-of-a-first-person-shooter here is an guide. Scroll down and you will se that, but you have one problem in your script. you cant takedamage from localscript. Fix it with remote events

0

I know about TakeDamage, but I'm not necessarily trying to make a FPS.