如何让队伍里的玩家检测玩家的部位?

我正在使用 WorldToScreenPointGetPartsObscuringTarget。我要修复的问题是:玩家必须检测不同队伍的玩家的部位。例如,有一个玩家独自一人组成一个队伍,试图通过检测他们的人形部位来找到其他玩家。这个脚本只能检测 Workspace 内的部位。

我尝试使用 Player.CharacterAdded:Wait() 和一个嵌套循环来检查玩家是否在同一个队伍里。但这没有效果。我已经努力解决这个问题已经两个星期了。

local Player = game.Players.LocalPlayer
local Character = workspace:FindFirstChild(Player.Name)

game:GetService("RunService").Heartbeat:Connect(function()
    for _, object in pairs(Character:GetDescendants()) do
        if object:IsA("Part") or object:IsA("MeshPart") then
            if not object:IsDescendantOf(game.Players.LocalPlayer.Character) then
                local object2,visible = workspace.CurrentCamera:WorldToScreenPoint(object.Position)
                if visible == true then
                    local pos1 = workspace.CurrentCamera.CFrame.Position
                    local pos2 = object.Position
                    local castPoints = {pos1,pos2}
                    local ignoreList = {game.Players.LocalPlayer.Character, object}
                    local obstructs = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints,ignoreList)
                    if obstructs[1] then
                        return
                    elseif not obstructs[1] then
                        print(object.Name.." 已被检测到!")
                    end
                elseif visible ~= true then
                        print("现在你处于隐身状态。")
                    return
                end
            end
        end
    end
end)
点赞