Advertisement
ShadowClawPlays

Placement

May 28th, 2022 (edited)
1,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.31 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local mouse = player:GetMouse()
  3.  
  4. local maxDistance = 20
  5.  
  6. local UIS = game:GetService("UserInputService")
  7. local RunService = game:GetService("RunService")
  8. local Anim = script:WaitForChild("Animation")
  9. local character = player.Character or player.CharacterAdded:Wait()
  10. local Humanoid = character:WaitForChild("Humanoid")
  11. local Handle = script.Parent:WaitForChild("Handle")
  12. local UI = player.PlayerGui:WaitForChild("StatusGui")
  13. local max = UI:WaitForChild("Max")
  14.  
  15. local ToolQuantity = player.PlayerGui:WaitForChild("ToolQuantity")
  16. local Quantity = ToolQuantity:WaitForChild("TextLabel")
  17.  
  18. local AnimTrack = Humanoid:LoadAnimation(Anim)
  19.  
  20. local placing = false
  21. local delete = false
  22.  
  23. --BLOCK
  24. local PlaceBlock = Instance.new("Part")
  25. PlaceBlock.Size = Vector3.new(3, 3, 3)
  26. PlaceBlock.Material = Enum.Material.SmoothPlastic
  27. PlaceBlock.Anchored = true
  28. PlaceBlock.CanCollide = false
  29. PlaceBlock.Transparency = 0.5
  30. PlaceBlock.BrickColor = BrickColor.new("New Yeller")
  31.  
  32. script.Parent.Equipped:Connect(function()
  33.     if placing == false then
  34.         ToolQuantity.Enabled = true
  35.         placing = true
  36.         delete = false
  37.     else
  38.         placing = false
  39.         PlaceBlock.Parent = nil
  40.     end
  41. end)
  42.  
  43. script.Parent.Unequipped:Connect(function()
  44.     if placing == false then
  45.         ToolQuantity.Enabled = false
  46.         placing = false
  47.         delete = false
  48.     else
  49.         placing = false
  50.         PlaceBlock.Parent = nil
  51.     end
  52. end)
  53.  
  54. RunService.RenderStepped:Connect(function() -- for placing
  55.     if placing == true then
  56.         PlaceBlock.Parent = game.Workspace -- putting parent for placement block
  57.         if mouse.Target ~= nil then
  58.             if mouse.Target.Name == "Block" or mouse.Target.Name == "Cannotdelete" then
  59.                 local target = mouse.Target
  60.                 local TargetSurface = mouse.TargetSurface
  61.  
  62.                 if TargetSurface.Name == "Top" then
  63.                     PlaceBlock.Position = target.Position + Vector3.new(0,3,0)--based on coordinates XYZ
  64.                 elseif TargetSurface.Name == "Bottom" then
  65.                     PlaceBlock.Position = target.Position + Vector3.new(0,-3,0) -- just copy       
  66.                 elseif TargetSurface.Name == "Right" then
  67.                     PlaceBlock.Position = target.Position + Vector3.new(3,0,0)
  68.                 elseif TargetSurface.Name == "Left" then
  69.                     PlaceBlock.Position = target.Position + Vector3.new(-3,0,0)
  70.                 elseif TargetSurface.Name == "Back" then
  71.                     PlaceBlock.Position = target.Position + Vector3.new(0,0,3)
  72.                 elseif TargetSurface.Name == "Front" then
  73.                     PlaceBlock.Position = target.Position + Vector3.new(0,0,-3)
  74.                 end
  75.             end
  76.         end
  77.     end
  78. end)
  79.  
  80. local function OnDeath()
  81.     game.Debris:AddItem(PlaceBlock, 0)
  82.     game.Debris:AddItem(script.Parent, 0)
  83. end
  84.  
  85. Humanoid.Died:Connect(OnDeath)
  86.  
  87. local Material = "Wool"
  88.  
  89. ----PLACING
  90.  
  91. local PlaceEvent = game.ReplicatedStorage.RemoteEvents.PlaceEvent
  92.  
  93.  
  94. script.Parent.Activated:Connect(function()
  95.     AnimTrack:Play()
  96.     if placing == true then
  97.         if mouse.Target ~= nil then
  98.             if (mouse.Target.Position - character.HumanoidRootPart.Position).Magnitude < maxDistance then
  99.                 PlaceEvent:FireServer(PlaceBlock.Position, Material)
  100.                 print("Place")
  101.                 local target = mouse.Target
  102.                 local TargetSurface = mouse.TargetSurface
  103.                 Handle.WoolValue.Value = Handle.WoolValue.Value - 1
  104.  
  105.                 if TargetSurface.Name == "Top" then
  106.                     PlaceBlock.Position = target.Position + Vector3.new(0,3,0)--based on coordinates XYZ
  107.                 elseif TargetSurface.Name == "Bottom" then
  108.                     PlaceBlock.Position = target.Position + Vector3.new(0,-3,0) -- just copy       
  109.                 elseif TargetSurface.Name == "Right" then
  110.                     PlaceBlock.Position = target.Position + Vector3.new(3,0,0)
  111.                 elseif TargetSurface.Name == "Left" then
  112.                     PlaceBlock.Position = target.Position + Vector3.new(-3,0,0)
  113.                 elseif TargetSurface.Name == "Back" then
  114.                     PlaceBlock.Position = target.Position + Vector3.new(0,0,3)
  115.                 elseif TargetSurface.Name == "Front" then
  116.                     PlaceBlock.Position = target.Position + Vector3.new(0,0,-3)
  117.                 end
  118.             end
  119.         end
  120.     else
  121.         max.Text = "You cannot place the block too far."
  122.         max.Visible = true
  123.         task.wait(4)
  124.         max.Visible = false
  125.     end
  126. end)
  127.  
  128. RunService.RenderStepped:Connect(function()
  129.     if Handle.WoolValue.Value == 0 or Handle.WoolValue.Value == -1 then
  130.         game.Debris:AddItem(PlaceBlock, 0)
  131.         game.Debris:AddItem(script.Parent, 0)
  132.     end
  133. end)
  134.  
  135. RunService.RenderStepped:Connect(function()
  136.     Quantity.Text = "Quantity: "..Handle.WoolValue.Value
  137. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement