Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to create a block when the tool is activated
- local function createBuildingTool()
- local tool = Instance.new("Tool")
- tool.Name = "BuildingTool"
- local handle = Instance.new("Part")
- handle.Name = "Handle"
- handle.Size = Vector3.new(4, 1, 4)
- handle.Anchored = true
- handle.CanCollide = false
- handle.BrickColor = BrickColor.new("Bright blue")
- handle.Transparency = 0.5
- handle.Parent = tool
- -- Function to place a block when the tool is activated by clicking
- tool.Activated:Connect(function()
- local character = tool.Parent
- local humanoid = character:FindFirstChild("Humanoid")
- if humanoid then
- local mouse = humanoid:GetMouse()
- local hit, position = workspace:FindPartOnRayWithIgnoreList(
- Ray.new(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 100),
- {character, tool}
- )
- if hit and hit:IsA("BasePart") then
- local newBlock = handle:Clone()
- newBlock.Position = position
- newBlock.Parent = workspace
- end
- end
- end)
- -- Function to remove placed blocks when right-clicked
- tool.Equipped:Connect(function()
- local character = tool.Parent
- local humanoid = character:FindFirstChild("Humanoid")
- if humanoid then
- local mouse = humanoid:GetMouse()
- mouse.Button2Down:Connect(function()
- local hit, position = workspace:FindPartOnRayWithIgnoreList(
- Ray.new(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 100),
- {character, tool}
- )
- if hit and hit:IsA("Part") then
- hit:Destroy()
- end
- end)
- end
- end)
- -- Function to drop the tool when unequipped
- tool.Unequipped:Connect(function()
- tool.Parent = game.Players.LocalPlayer.Character
- end)
- tool.Parent = game.Players.LocalPlayer.Backpack
- end
- -- Call the createBuildingTool function
- createBuildingTool()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement