Raycast blocked by Players

Hello!

The current issue I am dealing with revolves around Raycasting. I’m trying to make an ignore list for the raycast to ignore all other Characters in the workspace and therefore should not be obstructed by players. However, this only works when there are 2 players in the server. Any more than 2 players and the characters begin blocking one another’s raycasts.

The Script:

game:GetService("RunService").RenderStepped:Connect(function()

	local AllPlayers = game.Players:GetPlayers()
					
	for _, OtherPlayer in pairs(AllPlayers) do
					
		local char = player.Character or player.CharacterAdded:wait()
		local OtherChar = OtherPlayer.Character or OtherPlayer.CharacterAdded:wait()
				
		local ignoreList = {
			OtherChar,
			char			
		}			
				
		local ray = Ray.new(char.PrimaryPart.CFrame.p, Vector3.new(0,-1000,0))
		local object = workspace:FindPartOnRayWithIgnoreList(ray, ignoreList, false, false)

		if object and object.Name:match("MediumVotingPad") then
       --Rest of the script--

If anybody knows why the Ignore List does not take effect with 3 or more players in the game, please let me know below :+1:

The problem is that your are raycasting inside the for loop, so you only have “other character” and your self, what you need to do is first get the players and then raycast to the list of characters.
I guess it would be enough to make a new empity table, and then run a for loop that adds the player character to the table and finally add that table to the ignorelist

I may be completely wrong here, but game.Players is the list of Players who are playing your game but not the actual Character in the workspace. You need to look for the Character(s) in the workspace by name.

Try looking at the section of script that @Jackscarlett wrote in this post Issues checking player position help

The ignoreList only contains 2 characters, yours and some other player ones. I recommend writing down a function that basically returns ignoreList of all characters and you won’t have to use the loop at all.

local function returnIgnoreList()
   local ignoreList = {}
   for i, player in pairs(game.Players:GetChildren()) do
         if player.Character ~= nil then
            table.insert(ignoreList, player.Character)
         end
   end
   return ignoreList
end
local ignoreList = returnIgnoreList()
1 Like