Advertisement
Sungmingamerpro13

New Plank System (ToolScript (LocalScript))

Dec 11th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.04 KB | None | 0 0
  1. -- Define the Tool and player objects
  2. local Tool = script.Parent
  3. local player = game.Players.LocalPlayer
  4.  
  5. -- Wait for necessary GUI elements to load
  6. local backpackGui = player.PlayerGui:WaitForChild("BackpackGui")
  7. local planksDisplay = backpackGui.Frame:WaitForChild("Planks")
  8.  
  9. -- Get the player's mouse
  10. local mouse = player:GetMouse()
  11.  
  12. -- Function to update the planks count display
  13. local function updatePlanksDisplay()
  14.     if Tool:FindFirstChild("plankstacks") then
  15.         planksDisplay.TextLabel.Text = "Planks Left: " .. Tool.plankstacks.Value
  16.     else
  17.         warn("Tool is missing 'plankstacks' value!")
  18.     end
  19. end
  20.  
  21. -- Event triggered when the tool is equipped
  22. Tool.Equipped:Connect(function()
  23.     -- Show the planks counter in the GUI
  24.     planksDisplay.Visible = true
  25.  
  26.     -- Update the planks counter when 'plankstacks' value changes
  27.     if Tool:FindFirstChild("plankstacks") then
  28.         Tool.plankstacks:GetPropertyChangedSignal("Value"):Connect(updatePlanksDisplay)
  29.         updatePlanksDisplay()
  30.     else
  31.         warn("Tool is missing 'plankstacks' value!")
  32.     end
  33. end)
  34.  
  35. -- Event triggered when the tool is unequipped
  36. Tool.Unequipped:Connect(function()
  37.     -- Hide the planks counter in the GUI
  38.     planksDisplay.Visible = false
  39. end)
  40.  
  41. -- Event triggered when the tool is activated
  42. Tool.Activated:Connect(function()
  43.     -- Ensure there are planks available before placing one
  44.     if Tool:FindFirstChild("plankstacks") and Tool.plankstacks.Value > 0 then
  45.         -- Create a new plank part
  46.         local plank = Instance.new("Part")
  47.         plank.Name = "Plank"
  48.         plank.Anchored = true
  49.         plank.Material = Enum.Material.WoodPlanks
  50.         plank.Size = Vector3.new(9, 0.2, 2)
  51.         plank.Position = mouse.Hit.Position
  52.         plank.Orientation = Vector3.new(0, mouse.Origin.LookVector.Y * 90, 0) -- Adjust for proper rotation
  53.         plank.Color = Color3.fromRGB(105, 64, 40)
  54.  
  55.         -- Parent the plank to the workspace
  56.         plank.Parent = workspace
  57.  
  58.         -- Decrease the plank count
  59.         Tool.plankstacks.Value = Tool.plankstacks.Value - 1
  60.     else
  61.         warn("No planks left to place!")
  62.         planksDisplay.Visible = false
  63.         Tool:Destroy()
  64.     end
  65. end)
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement