Update: this problem has been solved by kingdom5 over on the SH discord server! All I had to do was find all the accessories in models in the workspace and add them to a list of ignored parts, then use FindPartOnRayWithIgnorList() with that ignore list. It worked!

I've got a crossbow script that I'm making, where you can charge back the crossbow and you will do damage depending on how much it's charged. If it has less than 90% charge, it will shoot a projectile at a specific speed that ignores accessories and hits targets just fine. However, if it's 90% charged or higher, it will fire a solid raycasted beam that instantly hits its target. The problem is, if the ray hits an accessory, it still counts as a hit and will damage the target. As you can imagine, this means a big disadvantage for anyone with large accessories, and if I add headshots, it means people with hair or certain other hats are at an advantage, since the accessory will be partially or completely blocking their head, meaning it'll be harder to get headshots on them. How would I make it so this raycasting script completely ignores accessories and goes through them instead of counting it as hitting something?

local ray = Ray.new(player.Character.Head.CFrame.p, (mouse.Hit.p - player.Character.Head.CFrame.p).unit * 300)
		
			local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

			if part then
				local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
 
				if not humanoid then
					humanoid = part.Parent.Parent:FindFirstChildOfClass("Humanoid")
				end

				if humanoid then
					if humanoid.Health > 0 then
						local targetplayer = game.Players:GetPlayerFromCharacter(part.Parent)
						if targetplayer then
							if targetplayer.TeamColor ~= player.TeamColor or targetplayer.Neutral == true then
								game.Workspace.DamageHumanoid:FireServer(humanoid, damage, part, script.Parent)
							end
						else
							game.Workspace.DamageHumanoid:FireServer(humanoid, (damage), part, script.Parent)
						end
					end
				end
			end
			game.Workspace.StaticBulletBeam:FireServer(BrickColor.new("Gold"), Enum.Material.Neon, 0, 0.5, 0.05, script.Parent.Handle.CFrame.p, position)

Yes, this is the raycasting laser gun script in the wiki, but I've made some important changes, like checking if the target is on your team and FE compatibility. But please, help me out with this. I don't want my game to be unfair for people with wings and people with hair.

3 comments

0

There's actually a much easier way to do this rather than ignoring accessories. You can find the humanoid with two tries like "hithuman = Hit.Parent:FindFirstChild("Humanoid") or Hit.Parent.Parent:FindFirstChild("Humanoid")" and then check if the hit object's parent is an accessory "Hit.Parent:IsA("Accessory")". If it is, turn the hit into the head like so: "Hit = hithuman.Parent.Head"

0

I could do that, but I'd rather have the ray go through accessories instead of counting them as hitting the head. Not all accessories are for the head. It wouldn't make sense for you to hit the swordpack on someone's back or some wings and have it register as hitting the head. I want it to pass through accessories, not count it as a headshot if it hits one.

0

If this question is answered, please put [solved] in the question title.