Raycast only detects model when I shoot past it

the raycast doesn’t detect a hit when i click on the face of the part, but if i click beyond the part, it does

this is the code I use for calculating the raycast

local ServerEvents = game.ServerStorage.ServerEvents
local Remotes = game.ReplicatedStorage.Remotes

local function computeRaycast(Player,origin,hitPos,fireTime)
	local direction = hitPos - origin

	local prams = RaycastParams.new()
	prams.IgnoreWater = true
	prams.FilterDescendantsInstances = {Player.Character}
	local ray = workspace:Raycast(origin,direction,prams)

	if ray then
		print(ray.Distance)
		print(ray.Instance)
		local hitmodel = ray.Instance:FindFirstAncestorWhichIsA("Model")
		if hitmodel then
			if hitmodel:FindFirstChild("Humanoid") then
				hitmodel.Humanoid.Health = 0
			elseif hitmodel:GetAttribute("IsDestructable") and hitmodel:GetAttribute("Destroyed") == false then
				print(hitmodel)
				ServerEvents.ServerClientIntDestruction:Fire(hitmodel)
			end
		end
	end
end

ServerEvents.ClientServerRaycastBackend.Event:Connect(computeRaycast)```

origin is the humanoidrootpart position
hitpos is mouse.hit.position
firetime is just os.clock that doesnt do anything
local ServerEvents = game.ServerStorage.ServerEvents
local Remotes = game.ReplicatedStorage.Remotes

local function computeRaycast(Player,origin,hitPos,fireTime)
	local direction = (hitPos - origin).Unit * 100000

	local prams = RaycastParams.new()
	prams.IgnoreWater = true
	prams.FilterDescendantsInstances = {Player.Character}
	local ray = workspace:Raycast(origin,direction,prams)

	if ray then
		print(ray.Distance)
		print(ray.Instance)
		local hitmodel = ray.Instance:FindFirstAncestorWhichIsA("Model")
		if hitmodel then
			if hitmodel:FindFirstChild("Humanoid") then
				hitmodel.Humanoid.Health = 0
			elseif hitmodel:GetAttribute("IsDestructable") and hitmodel:GetAttribute("Destroyed") == false then
				print(hitmodel)
				ServerEvents.ServerClientIntDestruction:Fire(hitmodel)
			end
		end
	end
end

ServerEvents.ClientServerRaycastBackend.Event:Connect(computeRaycast)

could you explain what you did, im trying to learn

1 Like

I’m really bad at English so I can’t :laughing:

1 Like

thanks anyways

1 Like

This should help you understand what was changed if you’d like to learn.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.