HowToRoblox

PlaceBlock

Jan 18th, 2021 (edited)
3,723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. local snap = 3
  2.  
  3.  
  4. game.ReplicatedStorage:WaitForChild("PlaceBlockRE").OnServerEvent:Connect(function(plr, blockType, target, targetSurface, removeOrPlace)
  5.    
  6.    
  7.     if removeOrPlace == "placing" then
  8.    
  9.         local position
  10.        
  11.         if targetSurface == Enum.NormalId.Top then
  12.             position = target.Position + Vector3.new(0, snap, 0)
  13.                
  14.         elseif targetSurface == Enum.NormalId.Bottom then
  15.             position = target.Position - Vector3.new(0, snap, 0)
  16.                
  17.         elseif targetSurface == Enum.NormalId.Left then
  18.             position = target.Position - Vector3.new(snap, 0, 0)
  19.                
  20.         elseif targetSurface == Enum.NormalId.Right then
  21.             position = target.Position + Vector3.new(snap, 0, 0)
  22.                
  23.         elseif targetSurface == Enum.NormalId.Front then
  24.             position = target.Position - Vector3.new(0, 0, snap)
  25.                
  26.         elseif targetSurface == Enum.NormalId.Back then
  27.             position = target.Position + Vector3.new(0, 0, snap)
  28.         end
  29.        
  30.            
  31.         local blockInPos
  32.            
  33.         for i, d in pairs(workspace:GetDescendants()) do
  34.                
  35.             if d:IsA("BasePart") and d.Position == position then blockInPos = true end
  36.         end
  37.            
  38.            
  39.         if not blockInPos and position then
  40.                
  41.             local newBlock = blockType:Clone()
  42.             newBlock.Size = Vector3.new(snap, snap, snap)
  43.             newBlock.Anchored = true
  44.            
  45.             newBlock.Position = position
  46.            
  47.             newBlock.Parent = workspace
  48.            
  49.             game.ReplicatedStorage.PlaySoundRE:FireClient(plr)
  50.         end
  51.        
  52.        
  53.     elseif removeOrPlace == "removing" then
  54.        
  55.         if target and target:FindFirstChild("Placeable") then
  56.             target:Destroy()
  57.            
  58.             game.ReplicatedStorage.PlaySoundRE:FireClient(plr)
  59.         end
  60.     end
  61. end)
  62.  
  63.  
  64.  
  65. local gridX, gridZ = 100, 100
  66.  
  67.  
  68. for x = 1, gridX do
  69.    
  70.     for z = 1, gridZ do
  71.        
  72.        
  73.         local block = game.ReplicatedStorage.Blocks.Grass:Clone()
  74.         block.Size = Vector3.new(snap, snap, snap)
  75.         block.Anchored = true
  76.        
  77.         block.Position = Vector3.new(snap * x, snap, snap * z)
  78.        
  79.         block.Parent = workspace
  80.     end
  81. end
Add Comment
Please, Sign In to add comment