Able to select players but not players behind walls

I’m trying to make a system like the Roblox Game “Dingus” where if you click on a character with a humanoid, it shoots it.

Right now I have it where it sends a raycast from the head to prevent from hitting behind walls, the problem is that if other players or characters are in front of the targetted character, it selects them because they are interrupting the raycast.

Is there any ideas to do this? Like click detectors? This is my first post sorry if it is low quality

This is what I want to achieve but instead you click on the characters

So you want to shoot a certain person, but other people can get in the way, and you don’t want that?

Hi oddblaster, welcome to the forum!

No worries about the post, you did a good job explaining your question! The correct category for help posts is in #help-and-feedback, specifically #help-and-feedback:scripting-support for programming questions.

If you want a raycast to ignore certain things, you can use a RaycastParams with an exclude list. You can then loop over the players and add their characters to the exclude list. That way, the raycast skips over any parts of player characters.

Here is some slightly modified code from GPT to explain:

-- Create a new RaycastParams object
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude

-- Add instances to the exclude list
local excludeList = {}  -- TODO: Get a list of the players' characters and put it here
raycastParams.FilterDescendantsInstances = excludeList

-- Using the raycast params, the raycast now knows to skip over all player characters
local raycastResult = workspace:Raycast(origin, direction * 100, raycastParams)  -- Example raycast, use your own origin and direction vector

To get a list of characters, you can do:

local Players = game:GetService("Players")

local excludeList = {}

for index, player in ipairs(Players:GetChildren()) do
    if player.Character then
        table.insert(excludeList, player.Character)
    end
end

Combining these, you can do a raycast that skips over any player characters that get in the way!

1 Like

you can just use mouse.Target and check if the model has a humanoid → shoot it

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