Why is FilterDescendantsInstances being ignored?

You know the drill, problems with scripting. What I’m trying to code is a ray that gets all the humanoids that goes through it and damages them.

The best approach I thought for this was after damaging the character, add them to the exclude table and then run the same raycast until there’s no more characters hitting it. The hit character is sent to the exclude table, however, the raycast still acts like that character is not the character to be ignored, causing an infinite yield.

I’ve tried to update my raycast params everytime the exclude table got a new character, however, that still didn’t work.

Anyways, here’s my script:

local FilterTable2 = {workspace.Map.Regions} 	
		local raycastParams2 = RaycastParams.new()
		raycastParams2.FilterDescendantsInstances = FilterTable2
		raycastParams2.FilterType = Enum.RaycastFilterType.Exclude
		
		local Raycast2 = workspace:Raycast(Pos, Direction * 500, raycastParams2)
		if Raycast2 and Cancelled ~= true then
			if Raycast2.Instance:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") then	
				local Humanoid = Raycast2.Instance:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid")
				if Humanoid.Health and Humanoid.Parent:FindFirstChild("CanDie") then
					if Humanoid.Parent.CanDie.Value == true then
						repeat
						Humanoid:TakeDamage(Damage)

						table.insert(FilterTable2, Humanoid:FindFirstAncestorWhichIsA("Model"))
						raycastParams2.FilterDescendantsInstances = FilterTable2
						Raycast2 = workspace:Raycast(Pos, Direction * 500, raycastParams2)
						until Raycast2 == nil or Raycast2.Instance:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") == nil
					end		
				end	
			end
		end

FilterTable2 is my exclude table.

Let me know if more info is required about the script, since I cut some parts of it to make it more readable.

Any help is appreciated :happy2: !

Figured it out, played around moving the repeat and until statements,worked when I moved the repeat statement below:

and moved the until statement accordingly.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.