Skip to content

Instantly share code, notes, and snippets.

@gamebox777
Created April 10, 2024 07:26
Show Gist options
  • Select an option

  • Save gamebox777/c6fde7b3702448cbfa49179aa06d139d to your computer and use it in GitHub Desktop.

Select an option

Save gamebox777/c6fde7b3702448cbfa49179aa06d139d to your computer and use it in GitHub Desktop.
roblox 当たったら死ぬ処理 ロブロックス
-- このスクリプトを死亡トリガーとしたいブロックにアタッチしてください。
-- タッチイベントを検出する関数
local function onTouched(other)
-- otherはタッチしたオブジェクト。この場合はプレイヤーのキャラクターの一部。
local character = other.Parent -- プレイヤーのキャラクターを取得
local humanoid = character:FindFirstChildOfClass("Humanoid") -- Humanoidオブジェクトを取得
-- Humanoidが存在し、生きている場合にのみ実行
if humanoid and humanoid.Health > 0 then
humanoid.Health = 0 -- HumanoidのHealthを0に設定し、キャラクターを「死亡」状態にする
end
end
-- このスクリプトがアタッチされたパーツのTouchedイベントに、上記の関数を接続
script.Parent.Touched:Connect(onTouched)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment