Raycast gun damaging player but he is in Raycast.FilterDescendantsInstances

So i making a Gun i can show you an example of whats wrong:


Code(i cant show you the entire code):

GEngine.Events.Shoot.OnServerInvoke = function(Player, Pos, GunFirePoint)
	local Raycast = RaycastParams.new()
	Raycast.FilterDescendantsInstances = {Player.Character}
	Raycast.FilterType = Enum.RaycastFilterType.Blacklist
	local Result = workspace:Raycast(Tool.Handle.Position, (Pos - Tool.Handle.Position) * Settings.Settings.Range)
	if Result then
		local Hit = Result.Instance
		local Model = Hit:FindFirstAncestorOfClass("Model")
		if Model then
			if Model.Humanoid then
				Model.Humanoid.Health -= Settings.Settings.Damage
				if Model.Humanoid.Health <= 0 then
					return true
				else
					return false
				end
			end
		end
	end
end

You didn’t pass in the Raycast params into the Raycast function, you only passed in the origin and direction

local Result = workspace:Raycast(Tool.Handle.Position, (Pos - Tool.Handle.Position) * Settings.Settings.Range)

Should be

local Result = workspace:Raycast(Tool.Handle.Position, (Pos - Tool.Handle.Position) * Settings.Settings.Range, Raycast)
1 Like

Probably you can use @Alvin_Blox’s 10 minute gun tutorial it works nice.

I used it too. I changed it a bit and it has headshot system too and the lasers are visible. Want the script?

No thanks im making my own (FPS) gun script

1 Like