humanoidからPlayerを取得

Humanoidから、Playerを取得する方法です。

local function onTouch(otherPart)
    local character = otherPart.Parent
    local humanoid = character:FindFirstChildWhichIsA("Humanoid")

    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(character)
        print(player.Name)    -- プレイヤー名をprint表示
    end
end

script.Parent.Touched:Connect(onTouch)

playerからHumanoidを取得(Local Script)

local character = game.Players.LocalPlayer.Character   -- LocatScriptのみ有効
local humanoid = character:FindFirstChildWhichIsA("Humanoid")

返信を残す