Raycasting script brocken?

I have this raycast script and for some reason it doesn’t damage the player any help?

script.Parent:WaitForChild("HumanoidRootPart")

local ammoStart = script.Parent.Ammo.Value
reload = false


script.Parent.Main.Shoot.OnServerEvent:Connect(function(player,mousePos)
	script.Parent:WaitForChild("HumanoidRootPart")
	if reload == false then
		local ammo1 = script.Parent.Ammo.Value
		if ammo1 >= 1 then
			script.Parent.Ammo.Value -= 1
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {player.Character}
			raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

			local raycastResult = workspace:Raycast(script.Parent.Handle.Position,(mousePos - script.Parent.Handle.Position)*1000,raycastParams)
			if raycastResult then
				local hitPart = raycastResult.Instance
				local model = hitPart:FindFirstAncestorOfClass("Model")

				if model then
					if model:FindFirstChild("Humanoid") then
						model.Humanoid.Health -= script.Parent.Damage.Value
					end
				end
			end
		else
			script.Parent.Handle.Reload:Play()
			reload = true
			script.Reloading.Value = true
			wait(script.Parent.Handle.Reload.TimeLength)
			script.Parent.Ammo.Value = ammoStart
			reload = false
			script.Reloading.Value = false
		end
	end
end)

Have you made sure that it gets a result?

I fixed it, I was using a viewmodel so i had to change the start pos

1 Like