RobloxのScriptでHumanoidを取得する方法
RobloxでHumanoidを取得するときによく使いそうなものをまとめる
- Characterから取得する
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
2. ゲームに参加したプレイヤーのHumanoidを取得する
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
end)
end)
3. パーツに触れたパーツからHumanoidを取得する
script.Parent.Touched:Connect(function(part)
-- 触れるパーツによってはcharacterとは限らないため確認が必要
local character = part.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
-- 何かしらの処理
end
end)
4. LocalScriptでHumanoidを取得する
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
関連
https://developer.roblox.com/en-us/api-reference/class/Humanoid