无法获取Roblox玩家属性值

问题描述 投票:0回答:1
script.Parent.Touched:Connect(function(player)
    print("TOUCHED")
    if player:GetAttribute("Hiding") then
        print("tag player touch????")
    else
        print("HMM")

    end
end)

这应该检测玩家而不是角色是否有标签。我知道玩家有标签。

roblox
1个回答
0
投票

.Touched
事件触发时,它将导致碰撞的工作区部分作为参数发送到您的自定义
.Touched
事件处理程序。您在此部分调用 GetAttribute,它包含在角色中。相反,向上父层次结构 (
touchedPart.Parent.Parent...
) 直到到达角色模型。

要从角色中找到玩家,请使用

local PlayerService = game.GetService("Players")
local player = PlayerService:GetPlayerFromCharacter( character )

您可以在这里找到更多信息:https://create.roblox.com/docs/building-and-visuals/physics/detecting-collisions

© www.soinside.com 2019 - 2024. All rights reserved.