I'm making a handgun and for some reason the raycasting isn't working, can someone help? It displays an error saying on line 14 it's a bad argument and should use Vector3 instead.

local Tool = script.Parent
local ShootEvent = Tool:WaitForChild("Shoot")
local ReloadEvent = Tool:WaitForChild("Reload")

ShootEvent.OnServerEvent:Connect(function(player,tool,part,position,damage)
	local beam = Instance.new("Part", workspace)
	beam.BrickColor = BrickColor.new("Medium stone grey")
	beam.Material = "Metal"
	beam.Transparency = 0.25
	beam.Anchored = true
	beam.Locked = true
	beam.CanCollide = false
		
	local distance = (tool.Handle.CFrame.p - position).magnitude
	beam.Size = Vector3.new(0.3, 0.3, distance)
	beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
		
	game:GetService("Debris"):AddItem(beam, 0.1)
	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(damage)
		end
	end
end)

1 comment

0

is the "position' argument a CFrame value or a Vector3 value