キャラクターとHumanoid:体力・歩く速さ・ジャンプ

初級キャラクター更新日:2026年11月13日Luauの型チェック済み

ひとことで言うと

プレイヤーのキャラクターは、パーツが集まったModelで、その中のHumanoidが体力や歩く速さを管理しています。ふれたものがプレイヤーかどうかは、Humanoidがあるか、またはPlayers:GetPlayerFromCharacterで調べます。

この記事で使うAPI

Humanoid・Player・Players・SpawnLocation

キャラクターのしくみ

  • キャラクター:プレイヤーの体。パーツ(頭・胴体など)が集まった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)
執筆・動作確認:鈴木孝昌官公庁のWeb・システム開発を担当する現役プロジェクトマネージャー。沖縄マイクラ部 クロスウェーブで、ロブロックス(Roblox)・マインクラフト(マイクラ)・Scratchなどのプログラミングを指導。マイクラカップ沖縄代表チームを指導(第6回・第7回、第7回TBS賞)。
沖縄マイクラ部で、子どもたちにロブロックス(Roblox)やマインクラフト(マイクラ)のプログラミングを教えています。プロフィールと編集方針
Instagramで教室の様子を見る
noteで記事を読む