SHARE
TWEET

g

a guest Sep 21st, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[ Item placement script
  2.  
  3. -- Variables
  4. local StoredPart = script.Parent.StoredPart.Value
  5. local player = game.Players.LocalPlayer
  6. local playerGui = player.PlayerGui
  7. local char = player.Character
  8. local mouse = player:GetMouse()
  9. local isPlacing = false
  10. local canPlace = false
  11. local mouseCFrame = mouse.Hit
  12. local mouseX = mouseCFrame.X
  13. local mouseY = mouseCFrame.Y
  14. local mouseZ = mouseCFrame.Z
  15.  
  16. -- Taking out the item, placing
  17. function placeItem()
  18.     isPlacing = true
  19.     StoredPart.Parent = workspace
  20.     StoredPart.Transparency = 0.25
  21.     StoredPart.CanCollide = false
  22.     mouse.Button1Down:Connect(function()
  23.             if canPlace == true then
  24.             isPlacing = false
  25.             StoredPart.Transparency = 0
  26.             StoredPart.CanCollide = true
  27.             StoredPart.Anchored = false
  28.             script.Parent:Destroy()
  29.         end
  30.     end)
  31. end
  32.  
  33.  
  34. -- Moving the item being placed
  35. function moveItem()
  36.     if isPlacing == true then
  37.          StoredPart.Position = Vector3.new(mouseX, mouseY, mouseZ)
  38.         else
  39.     end
  40. end
  41.  
  42.  
  43. -- Allowing/not allowing placement
  44. function allowPlacement()
  45.     local magnitude = (StoredPart.Position - char.Torso.Position).Magnitude
  46.     if magnitude < 15 then
  47.         canPlace = true
  48.     elseif magnitude > 15 then
  49.         canPlace = false
  50.     end
  51. end
  52.  
  53.  
  54. -- Running placeItem()
  55. script.Parent.MouseButton1Down:Connect(placeItem)
  56.  
  57.  
  58. -- Running moveItem() & allowPlacement()
  59. mouse.Move:Connect(function()
  60.     if isPlacing == true then
  61.     wait(0.1)
  62.     moveItem()
  63.     allowPlacement()
  64.     end
  65. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top