How to ignore all player characters using raycast Params

I’m trying to make blood system that will cast to all clients but the problem is that it doesn’t ignore other player characters it only ignores my character. I tried to add the raycastParams in the server script and made it into a parameter to the FireAllClients and grab it in the local script but the problem is that it spawns under ground and I can’t find solutions in the dev forum. The reason why I’m doing this so I can add a disable button for the blood.

This is the server script that will fire to all clients

local ReplicatedStorage = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.MaxHealth = 5000
		character.Humanoid.Health = 5000
		
		local lastHealth = character.Humanoid.Health
		local humanoidRootPart = character.HumanoidRootPart
		character.Humanoid.HealthChanged:Connect(function(health)
			if health < lastHealth then
				ReplicatedStorage.Remotes.Blood:FireAllClients()
				print("fired")
				lastHealth = health
			end
		end)
	end)
end)

This is the Local script for the clients to recieve:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BLOOD_COUNT = 10

local BloodTextures = {
	3213415529,
	3213415014,
	3213416072,
	3213414394,
	3213416072
}

local character = script.Parent
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local rng = Random.new()

ReplicatedStorage.Remotes.Blood.OnClientEvent:Connect(function()
	for i = 1, BLOOD_COUNT do
		local rayDirection = rng:NextUnitVector() * 10
		local rayOrigin = humanoidRootPart.Position
		
		local rayParams = RaycastParams.new()
			rayParams.FilterType = Enum.RaycastFilterType.Blacklist
			rayParams.FilterDescendantsInstances = {character, workspace.Fx}
			rayParams.IgnoreWater = true

		local result = workspace:Raycast(rayOrigin, rayDirection, rayParams)
		
		if result then
			local pos = result.Position
			local normal = result.Normal
			local instance = result.Instance
			
			local randomSize = math.random(3, 4)
			local part = Instance.new("Part")
			part.Size = Vector3.new(randomSize, randomSize, 0.05)
			part.Transparency = 1
			part.CanCollide = false
			part.Material = Enum.Material.SmoothPlastic
			part.Anchored = false

			local decal = Instance.new("Decal")
			decal.Texture = "rbxassetid://" .. BloodTextures[math.random(1 , #BloodTextures)]
			decal.Parent = part
			decal.Color3 = Color3.fromRGB(117, 0, 0)

			local weld = Instance.new("WeldConstraint")
			weld.Part0 = instance
			weld.Part1 = part
			weld.Parent = part

			part.CFrame = CFrame.lookAt(pos, pos + normal)
			part.Parent = workspace.Fx
			
			game.Debris:AddItem(part, 20)
		end
	end
end)
1 Like

You could try this, first get all the players by using “game.Players:GetChildren()” then loop through them and add them to your ignore list

example code:

local ignore_list = {character}
		
for i,v in pairs(game:GetService("Players"):GetChildren()) do
	if v then
		local v_char = v.Character or v.CharacterAdded:Wait()
				
		if v_char then
			table.insert(ignore_list, v_char)
		end
	end
end
		
local raycast_params = RaycastParams.new()
raycast_params.FilterDescendantsInstances = ignore_list
raycast_params.FilterType = Enum.RaycastFilterType.Blacklist
local raycast_result = workspace:Raycast(ray_origin, ray_direction, raycast_params)

if raycast_result then
    --do something
end
1 Like

Can’t you just do something like this (if I’m not mistaken)?

local params = Players:GetPlayers()
table.insert(params, workspace.Fx) -- OPTIONAL

rayParams.FilterDescendantsInstances = params 
1 Like

That won’t work you need to get the characters of the players

yes the “Players:GetPlayers” will work that’s optional and it gets the player not the character

so the method of looping through the table and getting the characters and inserting them is the correct method in my opinion

Well, you are right, except you made it a bit complicated.

You do not need to check if v is not nil since GetChildren doesn’t return blank values.

Waiting for the character to spawn when doing instant functions is not a good idea.

RaycastParams default FilterType is Blacklist so no need to set it to its current form.

local ignore_list = {}
		
for _,plr in ipairs(game:GetService("Players"):GetPlayers()) do
	local char = v.Character

	if char then
		ignore_list[#ignore_list+1] = char
	end
end
		
local raycast_params = RaycastParams.new()
raycast_params.FilterDescendantsInstances = ignore_list
local raycast_result = workspace:Raycast(ray_origin, ray_direction, raycast_params)

if raycast_result then
	--do something
end
2 Likes

found a better way, i’ll just use Group Collision

1 Like

Your for-loop isn’t written correctly, plr should be replaced with v or vice versa.

Also you can shorten your code a bit:

	for _,player in ipairs(game.Players:GetPlayers()) do
		if player.Character then -- check if character has spawned
			table.insert(chars, player.Character)
		end
	end

:slight_smile:

You’re right I didn’t see that

The time I wrote my code, using table[#table+1] = value was faster than using table.insert. Also, I didn’t want to index .Character twice so I put it in a variable