Raycast is acting weid

Hello there, I currently made a pistol that works fine but for some reason the ray is not detecting player even if I hit them, I currently have no idea why ray cast does this, I thought it could be that I hit handle of accesory but thats not true

My script:

local RayResult = workspace:Raycast(script.Parent.Handle.ShootAttachment.WorldPosition,RayDirection,ParamsToGood)

		if RayResult then
			local hit = RayResult.Instance
			Click(RayResult.Position)
			if hit then
				if hit.Parent:FindFirstChild("Humanoid") then
					if game.Players:FindFirstChild(hit.Parent.Name) then
						local SadBoi = game.Players[hit.Parent.Name]
						if SadBoi.Team == game.Teams.Fingers and SadBoi.Hostage.Value == false and SadBoi.Character.Humanoid.Health ~= 0 then
							SadBoi.Character.Humanoid.Health -= math.random(10,25) 

							local Result = workspace:Raycast(SadBoi.Character.HumanoidRootPart.Position,Vector3.new(0,-100,0))
							print("no result")
							if Result then
								print("result")
								local Blood = game.ReplicatedStorage.Blood:Clone()
								Blood.Position = SadBoi.Character.LeftFoot.Position - Vector3.new(0,0.1,0)
								Blood.Parent = workspace
								Blood.Effect.Disabled = false
							end
							
							if game.ServerScriptService.grab:FindFirstChild(SadBoi.Name) then
								game.ServerScriptService.grab.InteruptGrab:Fire(game.Players[game.ServerScriptService.grab[SadBoi.Name].Hostage.Value],"save")
							end

							if SadBoi.Character.Humanoid.Health <= 0 then
								Player.leaderstats.Money.Value += 30
								game:GetService("ReplicatedStorage").RemoteEvents.Money:FireClient(plr,30)
							end
						end
					elseif hit.Name == "Handle" then
						local SadBoi = game.Players[hit.Parent.Parent.Name]
						if SadBoi then
							if SadBoi.Team == game.Teams.Fingers and SadBoi.Hostage.Value == false and SadBoi.Character.Humanoid.Health ~= 0 then
								SadBoi.Character.Humanoid.Health -= math.random(10,25) 
								
								local Result = workspace:Raycast(SadBoi.Character.HumanoidRootPart.Position,Vector3.new(0,-100,0))
								print("no result")
								if Result then
									print("result")
									local Blood = game.ReplicatedStorage.Blood:Clone()
									Blood.Position = SadBoi.Character.LeftFoot.Position - Vector3.new(0,0.1,0)
									Blood.Parent = workspace
									Blood.Effect.Disabled = false
								end

								if game.ServerScriptService.grab:FindFirstChild(SadBoi.Name) then
									game.ServerScriptService.grab.InteruptGrab:Fire(game.Players[game.ServerScriptService.grab[SadBoi.Name].Hostage.Value],"save")
								end

								if SadBoi.Character.Humanoid.Health <= 0 then
									Player.leaderstats.Money.Value += 30
									game:GetService("ReplicatedStorage").RemoteEvents.Money:FireClient(plr,30)
								end
							end
						end
					end
				end
			end
		end

The direction Im calculating:

script.Parent.Activated:Connect(function()
	local Mouse = game.Players.LocalPlayer:GetMouse()
	script.Parent.ShootEvent:FireServer((Mouse.Hit.Position - script.Parent.Handle.ShootAttachment.WorldPosition).Unit * 100,Mouse.Target)
end)

Sometimes it works but most of time I shoot player and it do not detect hit!
Thanks!

1 Like