LoginSignup
6
2

More than 3 years have passed since last update.

Robloxで武器を作る、そして振る

Last updated at Posted at 2019-11-29

概要

image.png

手順

1. workspaceに「Tool」を追加。名前は適当にBomb

2. 追加したBombの下に、ScriptとPartを追加。Partの名前は必ず「Handle」にする

image.png

3. Scriptの中身

Script.lua

local tool = script.Parent

local function onTouch(partOther)
    -- あたったものが人間かどうか判断
    local humanOther = partOther.Parent:FindFirstChild("Humanoid")
    -- 人間じゃなかったら何もしない
    if not humanOther then return end   
    -- 人間だけど、自分自身だったら何もしない 
    if humanOther.Parent == tool.Parent then return end
    -- それ以外、つまり人間で、他人なら、ダメージが5当たる
    humanOther:TakeDamage(5)
end

-- 攻撃の動作
local function slash()
    local str = Instance.new("StringValue")
    str.Name = "toolanim"
    str.Value = "Slash"
    str.Parent = tool
end

-- Activatedは、「装備してる状態で左クリックを押す」のこと
-- 左クリックしたらslashの動作をする
tool.Activated:Connect(slash)

-- もし武器に当たったら、onTouch関数が起動する
tool.Handle.Touched:Connect(onTouch)

使い方

  • ぶつかるだけで武器がひろえる
  • 「1」をおせば装備できる
  • マウスの左クリックで攻撃

ゲーム開始時に最初から持たせたいとき

  • StarterPackフォルダにBombをいれておくだけ

image.png

練習用の殴る相手の出し方

  • HOMEのTOOLBOXをひらいて、「player」で検索するとたくさんでてくる

image.png

引用元

追記 2019/12/6

武器を装備すると地面にめり込んでしまう問題

image.png

  • 解決方法
    • Handle(Partオブジェクト)の中のWeldを消す、これだけ

image.png

6
2
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
6
2