Advertisement
HowToRoblox

PlaceStructure

Feb 13th, 2023
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. local maxRange = 30
  2.  
  3. function placeStructure(plrPlacing:Player, structure:Model, cf:CFrame)
  4.    
  5.     local char = plrPlacing.Character
  6.     if char and char:FindFirstChild("Humanoid") and char.Humanoid.Health > 0 then
  7.        
  8.         local distance = (char.HumanoidRootPart.Position - cf.Position).Magnitude
  9.         if distance <= maxRange then
  10.    
  11.             local newStructure = structure:Clone()
  12.            
  13.             newStructure:PivotTo(cf)
  14.            
  15.             newStructure.PrimaryPart.Parent = newStructure
  16.             newStructure.PrimaryPart.Name = "HumanoidRootPart"
  17.            
  18.             local humanoid = Instance.new("Humanoid")
  19.             humanoid.MaxHealth = newStructure.Health.Value
  20.             humanoid.Health = humanoid.MaxHealth
  21.             humanoid.Parent = newStructure
  22.            
  23.             humanoid.HealthChanged:Connect(function(health)
  24.                 if health == 0 then
  25.                     newStructure:Destroy()
  26.                 end
  27.             end)
  28.            
  29.             newStructure.Parent = workspace["STRUCTURES"]
  30.         end
  31.     end
  32. end
  33.  
  34. return placeStructure
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement