キャラクターとHumanoid:体力・歩く速さ・ジャンプ
初級キャラクター更新日:2026年11月13日Luauの型チェック済み
ひとことで言うと
プレイヤーのキャラクターは、パーツが集まったModelで、その中のHumanoidが体力や歩く速さを管理しています。ふれたものがプレイヤーかどうかは、Humanoidがあるか、またはPlayers:GetPlayerFromCharacterで調べます。
この記事で使うAPI
キャラクターのしくみ
- キャラクター:プレイヤーの体。パーツ(頭・胴体など)が集まったModelです。
- Humanoid:体力(Health)・歩く速さ(WalkSpeed)・ジャンプなどを管理します。
- HumanoidRootPart:キャラクターの中心のパーツ。位置を動かすときの基準になります。
ふれたのがプレイヤーか調べる
Touchedで渡されるのは、ふれたパーツ(足など)です。その親(hit.Parent)がキャラクターなので、そこにHumanoidがあるかを調べます。
(Script/置く場所:パーツの中)
local part = script.Parent :: BasePart
part.Touched:Connect(function(hit)
local character = hit.Parent
if not character then
return
end
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid.Health = 0
end
end)
歩く速さを変える
(Script/置く場所:ServerScriptService)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
humanoid.WalkSpeed = 32
end)
end)
チェックポイント
(Script/置く場所:SpawnLocationの中)
local Players = game:GetService("Players")
local checkpoint = script.Parent :: SpawnLocation
checkpoint.Touched:Connect(function(hit)
local character = hit.Parent
if not character or not character:IsA("Model") then
return
end
local player = Players:GetPlayerFromCharacter(character)
if player then
player.RespawnLocation = checkpoint
end
end)