Advertisement
HowToRoblox

PlaceFurniture

Jun 2nd, 2021
2,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. game.ReplicatedStorage:WaitForChild("PlaceFurnitureRE").OnServerEvent:Connect(function(plr, furniture, cframe, placing, plot)
  2.    
  3.     if placing then
  4.        
  5.         local pos = cframe.Position
  6.        
  7.         local lowerX, lowerZ = plot.Position.X - plot.Size.X/2, plot.Position.Z - plot.Size.Z/2
  8.         local upperX, upperZ = plot.Position.X + plot.Size.X/2, plot.Position.Z + plot.Size.Z/2
  9.        
  10.         if pos.X < upperX and pos.X > lowerX and pos.Z < upperZ and pos.Z > lowerZ then
  11.            
  12.             local furnitureClone = furniture:Clone()
  13.             furnitureClone:SetPrimaryPartCFrame(cframe)
  14.            
  15.             for i, d in pairs(furnitureClone:GetDescendants()) do
  16.                 if d:IsA("BasePart") then d.Transparency = 1; d.CanCollide = false end
  17.             end
  18.            
  19.             furnitureClone.Parent = workspace
  20.            
  21.             furnitureClone.PrimaryPart.Touched:Connect(function()end)
  22.            
  23.            
  24.             local touchingParts = furnitureClone.PrimaryPart:GetTouchingParts()
  25.            
  26.             for i, touchingPart in pairs(touchingParts) do
  27.                
  28.                 if touchingPart.Name == "Hitbox" then furnitureClone:Destroy(); return end
  29.             end
  30.            
  31.            
  32.             for i, d in pairs(furnitureClone:GetDescendants()) do
  33.                 if d:IsA("BasePart") and d.Name ~= "Hitbox" and not d:IsA("Seat") then d.Transparency = 0; d.CanCollide = true end
  34.             end
  35.         end
  36.        
  37.     elseif furniture then
  38.  
  39.         if furniture.Parent.Parent:FindFirstChild("Hitbox") then furniture.Parent.Parent:Destroy() end
  40.     end
  41. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement