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)