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
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!