見出し画像

【Roblox Studio】手持ちアイテムをQキーでドロップさせる方方法

※デフォルトで「Back Space」キーを押すとドロップさせることができるようになっていますが、指定のキーに変更したい場合はこちらを参照してください。

①「ReplicatedStorage」に「RemoteEvent」を設置。
②名前を「DropEvent」にする。

③「ServerScriptService」に「Script」を設置。
④「Script」本文に下記のものをコピペ。

local ReplicatedStorage = game:GetService('ReplicatedStorage')



local dropEvent = ReplicatedStorage:WaitForChild('DropEvent')



dropEvent.OnServerEvent:Connect(function(player)

	local playerModel = game.Workspace:FindFirstChild(player.Name)

	if playerModel then

		local tool = playerModel:FindFirstChildWhichIsA('Tool')

                if tool then

		    tool.Parent = game.Workspace

                end

	end

end)

⑤「StarterPlayer」>「StarterPlayerScripts」に「LocalScript」を設置。
⑥「LocalScript」本文に下記のものをコピペ。

local userInput = game:GetService("UserInputService")



local player = game.Players.LocalPlayer



local ReplicatedStorage = game:GetService('ReplicatedStorage')



local dropEvent = ReplicatedStorage:WaitForChild('DropEvent')



local function drop(input, gameProcessed)

    if not gameProcessed then        

        if input.UserInputType == Enum.UserInputType.Keyboard then

            local keycode = input.KeyCode

            if keycode == Enum.KeyCode.Q then

		dropEvent:FireServer()

            end

        end

    end

end



userInput.InputBegan:Connect(drop)

★Q以外の別のキーに変更する場合は
if keycode == Enum.KeyCode.Q then
ここの「Q」を別の文字に変える。

この記事が気に入ったらサポートをしてみませんか?