#Problem with raycast

1 messages · Page 1 of 1 (latest)

honest depot
#

script:

local replicatedEvents = game.ReplicatedStorage.Events
local shootRE = replicatedEvents.ShootGun
local shootVisualsRE = replicatedEvents.ShootGunVisuals

shootRE.OnServerEvent:Connect(function(plr: Player, tool: Tool, camCF: CFrame,  mouseCF: CFrame)
    
    local char = plr.Character
    local root = char:FindFirstChild("HumanoidRootPart")
    
    if tool and tool.Name == "Revolver" and root then
        local config = tool.Configuration
        if config.IsOnCooldown.Value == false then
            config.IsOnCooldown.Value = true
            tool.Handle.ShootSound:Play()
            local rp = RaycastParams.new()
            rp.FilterType = Enum.RaycastFilterType.Exclude
            rp.FilterDescendantsInstances = {char}
            
            local direction = (mouseCF.Position - camCF.Position).Unit
            local rayCast = workspace:Raycast(camCF.Position, direction * config.RaycastDepth.Value, rp)
            
            if rayCast then
                local hum = rayCast.Instance.Parent:FindFirstChild("Humanoid") or rayCast.Instance.Parent.Parent:FindFirstChild("Humanoid")
                if hum and hum.Health > 0 then
                    if game.Players:GetPlayerFromCharacter(hum.Parent) and not hum.Parent:FindFirstChild("MurdererKnife") and not game.Players:GetPlayerFromCharacter(hum.Parent).Backpack:FindFirstChild("MurdererKnife") then    
                        char.Humanoid.Health = 0
                    end
                    hum.Health = 0
                end
            end
            
            shootVisualsRE:FireAllClients(tool, rayCast and rayCast.Position or mouseCF.Position)
            
            task.wait(config.ShootCooldown.Value)
            
            if config and config:FindFirstChild("IsOnCooldown") then
                config.IsOnCooldown.Value = false
            end
        end
    end
end)
#

it lets me kill the target even from this angle

bleak crypt
#

You're shooting from camera, shoot from actual gun instead?

untold herald
#

Yes

#

I suggest you make an attachment in the gun that will be used as the fire point , that's what I do when I make weapons

#

And then shoot the ray from the attachment towards the mouse (or towards the attachment.CFrame.LookVector if you want something a bit more "realistic")

pine charm
#

Imo always shoot the raycast from the center of the humanoid when you do guns and whatnot

#

Just have the visuals show off as the gun firing it

#

The gun can sometimes bleed through walls and thus send false positives

honest depot
#

Oh, but the issue is when i zoom out like u know what I mean?