So yeah right now, I’m having an issue/trouble about the detected player character behind another player character in Server Script But I don’t know how to do it, I just went searching through all the devforum threads but all ended up client-side.
Why do you want to detect from the Server Side?
The reason I don’t want it to be client-side is that to be safe for myself, I don’t want the script getting decompiled by a handy software user.
If I understand what you’re trying to do, you should add all player’s characters to a blacklist in the raycast params to just ignore them when you cast the ray.
If you put all the players’ characters on the blacklist, The ray from the source part will not hit the character Because player’s Character is Blacklisted.
You would blacklist every character other than the local character. If that’s a problem then you can just cast another ray in the same direction originating from the first ray’s hit if you detect that ray hit a character to see if any other players are behind the one player.
Maybe do a small loop where it casts a ray and if it hits a character (finds a humanoid in what it just hit) then store the character and cast a second ray with that character blacklisted in filtering. And then repeat that loop until no character is hit.
Something like this:
local RaycastFinished = false
repeat
if Character:FindFirstChild("HumanoidRootPart") then
local OtherCharacters = {}
local rayOrigin = Character.HumanoidRootPart.Position
local rayDirection = game.Workspace.Part.CFrame.LookVector
-- Build a "RaycastParams" object and cast the ray
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Character, OtherCharacters}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
if hitPart.Parent:FindFirstChild("Humanoid") then --Found a "Humanoid"
if hitPart.Parent.Humanoid:IsA("Humanoid") then --Verifies that it is a real Humanoid instance
--Insert it into table
else
RaycastFinished = true
end
else
RaycastFinished = true
end
end
else
RaycastFinished = true
end
wait()
until RaycastFinished == true
Not sure if this actually works. Hopefully you get what I’m saying though.
Sorry if the script is confusing I just quickly put it together.
As what @drewbluewasabi said, you need to make recursive raycast, by checking whether hit part is a descendant of player character. If criteria is met, store and add them to ignore list, and re-cast ray until hit part is solid or is a descendant of local player character.