How do I get all the player characters in my game in my local script?

I use OverlapParams for my hit detection.

I need to detect all the Player’s Characters inside the game EXCEPT MINE! (Because sometimes the tool detects my own Character)

How can I do that in a Local Script?

	local OverlapParam = OverlapParams.new()
	OverlapParam.FilterDescendantsInstances = {workspace.Nods} -- I need to to detect the characters to make them hitable and make the local character not hitable
	OverlapParam.FilterType = Enum.RaycastFilterType.Whitelist

Thank you!

1 Like
local filteredChars = {workspace.Nods}
for _, plr in pairs(game.Players:GetPlayers()) do
    local char = plr.Character or plr.CharacterAdded:Wait()
    if char == game.Players.LocalPlayer.Character then continue end
    table.insert(filteredChars, char)
end

but does OverlapParam.FilterDescendantsInstances accept tables? I must get the model of the character itself

just add workspace.nods to the filteredCharsTable

1 Like
local Player = game.Players.LocalPlayer

for _, Char in pairs(game.Workspace:GetChildren())do
	if Char:IsA("Model") and game.Players:FindFirstChild(Char.Name) and not Char.Name == Player.Name then
		print(Char.Name)
	end
end

This as also an array so it should except the array of characters aswell.

1 Like
	local AbleToHitTable = {}
	
	for index, player in pairs(game:GetService("Players"):GetPlayers()) do
		local char = player.Character or player.CharacterAdded:Wait()
		table.insert(AbleToHitTable, char)
	end
	
	local MyOwnCharacterIndex = table.find(AbleToHitTable, Character) --Character represents my LocalPlayer's Character

	table.remove(AbleToHitTable, MyOwnCharacterIndex)
	
	table.insert(AbleToHitTable, workspace.Nods)
	
	local OverlapParam = OverlapParams.new()
	OverlapParam.FilterDescendantsInstances = AbleToHitTable 
	OverlapParam.FilterType = Enum.RaycastFilterType.Whitelist

This is how I fixed it! Thank you guys for the help!

1 Like

This is just a much a longer and dirtier version of the code I gave above

1 Like