サイトアイコン schilverberch★ROBLOX

パーツ生成をツールで作る

クリックしたところにパーツを置くツールを作成します。

  1. WorkspaceにToolを追加します。
  2. Toolの中にPartを入れます。
  3. Partの名称をHandleに変えます。
  4. ToolをStarterPackに移動します。
  5. Toolの中にRemoteEventを追加します。(クライアントからサーバープログラムを実行するため)
  6. Toolの中にLocalScriptを追加します。(クライアントで動作するプログラム)
  7. Toolの中にScriptを追加します。(サーバーで動作するプログラム)
  8. LocalScriptとScriptに次のプログラムを入れます。

LocalScriptのプログラム

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local tool = script.Parent
local remoteEvent = tool:WaitForChild("RemoteEvent")
local REACH = 100	-- どのくらい先までクリックが有効か

function OnEquipped(mouse)
	mouse.Button1Down:Connect(function()
		local unitRay = mouse.UnitRay
		local ray = Ray.new(unitRay.Origin, unitRay.Direction * REACH)

		local hit, pos, normal = game.Workspace:FindPartOnRay(ray, player.Character)
		if hit then
			remoteEvent:FireServer(pos)
			wait(0.5)
		end
	end)
end

tool.Equipped:connect(OnEquipped)

Scriptのプログラム

local tool = script.Parent
local remoteEvent = tool:WaitForChild("RemoteEvent")

function putBlock(player,position)
	local part = Instance.new("Part")
	part.Size = Vector3.new(3,3,3)
	part.Position = position
	part.Parent = game.Workspace
end

remoteEvent.OnServerEvent:Connect(putBlock)

RemoteEventも使わずに、LocalScript上でputBlockを行うと、クライアントだけが見えるパーツが生成できます。

モバイルバージョンを終了