2
1

More than 3 years have passed since last update.

Robloxで爆弾をつくる

Last updated at Posted at 2019-11-15

画像イメージ

image.png
image.png

  • ServerScriptServiceの中にScriptを追加。名前はBombGenerator
  • PartでSphereをつくり、名前はBombにする。ServerStorageへ移動させる。
  • BombにScriptを追加して、名前はBombScriptにする。
  • (完成図は以下の赤いわくのとおり) image.png

プログラミングの中身

BombGenerator.lua
local Debris = game:GetService("Debris")
-- ServerStorageの中のBombを取得してbomb変数に入れる
local bomb = game:GetService("ServerStorage").Bomb

while(1) do
  wait(1)   
  -- workspaceにBombオブジェクトが無ければ、新しくクローンする
  local isBomb = workspace:FindFirstChild("Bomb")
  if (not isBomb) then
      -- 爆弾を1つクローンする
      local clonedBomb = bomb:clone()

      -- 適当な場所に置く
      clonedBomb.Position = Vector3.new(-10, 2, 200)
      clonedBomb.Parent = workspace

      -- Debrisサービスに追加することでマップ上に姿を表す
      Debris:AddItem(clonedBomb, 20)
  end
end
BombScript.lua
-- BombにぶつかったPartが、hitという引数に入る
-- Playerは複数のPartで作られています。
local function explosion(hit)
  -- hitの親、つまりPlayerオブジェクトをtouchObject変数にいれます
  local touchObject = hit.Parent
  -- もしぶつかってきたものがHumanoidという子オブジェクトを持っていたら爆発します
  -- PlayerオブジェクトだけがHumanoidという子オブジェクトを持っています
  local humanoid = touchObject:FindFirstChildWhichIsA("Humanoid")
  if humanoid then      
    local exp = Instance.new('Explosion')
        exp.Position = hit.Position
        exp.Parent = workspace
    end
end

-- Workspace内のBombに触れたら、explosion関数が起動する
Workspace.Bomb.Touched:connect(explosion)

元記事

https://developer.roblox.com/en-us/recipes/How-to-kill-a-Roblox-character-with-kill

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1