I tried to make a raycast gun here is the script :

local tool = script.Parent local player = game:GetService("Players").LocalPlayer

tool.Equipped:Connect(function(mouse) print("Tool equipped!")

mouse.Button1Down:Connect(function()
	print("Tool Activated!")
	local ray = Ray.new(tool.Handle.CFrame.Position (mouse.Hit.Position - tool.Handle.CFrame.Position).unit * 300)
	local Part, Position = workspace:FindPartOnRay(ray, player.Character, false, true)
	
	local beam = Instance.new("Part")
	beam.BrickColor = BrickColor.new("Bright red")
	beam.Material = "Neon"
	beam.Transparency = 0.25
	beam.Anchored = true
	beam.Locked = true
	beam.CanCollide = false
	
	local distance = (tool.Handle.CFrame.Position - Position).magnitude
	beam.Size = Vector3.new(0.3, 0.3, distance)
	beam.CFrame = (tool.Handle.CFrame.Position) * CFrame.new(0,0,-distance / 2)
end)

end)

2 comments

0

It needs to be a localscript inside your tool cause this has to run on the client at least with the rendering part. Damaging you'll need a remote event. If not the only other thing I can think of is your not parenting beam to workspace.

0

show me the entire scirpt