Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the Tool and player objects
- local Tool = script.Parent
- local player = game.Players.LocalPlayer
- -- Wait for necessary GUI elements to load
- local backpackGui = player.PlayerGui:WaitForChild("BackpackGui")
- local planksDisplay = backpackGui.Frame:WaitForChild("Planks")
- -- Get the player's mouse
- local mouse = player:GetMouse()
- -- Function to update the planks count display
- local function updatePlanksDisplay()
- if Tool:FindFirstChild("plankstacks") then
- planksDisplay.TextLabel.Text = "Planks Left: " .. Tool.plankstacks.Value
- else
- warn("Tool is missing 'plankstacks' value!")
- end
- end
- -- Event triggered when the tool is equipped
- Tool.Equipped:Connect(function()
- -- Show the planks counter in the GUI
- planksDisplay.Visible = true
- -- Update the planks counter when 'plankstacks' value changes
- if Tool:FindFirstChild("plankstacks") then
- Tool.plankstacks:GetPropertyChangedSignal("Value"):Connect(updatePlanksDisplay)
- updatePlanksDisplay()
- else
- warn("Tool is missing 'plankstacks' value!")
- end
- end)
- -- Event triggered when the tool is unequipped
- Tool.Unequipped:Connect(function()
- -- Hide the planks counter in the GUI
- planksDisplay.Visible = false
- end)
- -- Event triggered when the tool is activated
- Tool.Activated:Connect(function()
- -- Ensure there are planks available before placing one
- if Tool:FindFirstChild("plankstacks") and Tool.plankstacks.Value > 0 then
- -- Create a new plank part
- local plank = Instance.new("Part")
- plank.Name = "Plank"
- plank.Anchored = true
- plank.Material = Enum.Material.WoodPlanks
- plank.Size = Vector3.new(9, 0.2, 2)
- plank.Position = mouse.Hit.Position
- plank.Orientation = Vector3.new(0, mouse.Origin.LookVector.Y * 90, 0) -- Adjust for proper rotation
- plank.Color = Color3.fromRGB(105, 64, 40)
- -- Parent the plank to the workspace
- plank.Parent = workspace
- -- Decrease the plank count
- Tool.plankstacks.Value = Tool.plankstacks.Value - 1
- else
- warn("No planks left to place!")
- planksDisplay.Visible = false
- Tool:Destroy()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement