Advertisement
karbis

randomizer script

Mar 1st, 2021 (edited)
29,721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.74 KB | None | 0 0
  1. --[[a script that randomizes the map, made for roblox]]
  2. --[[levels:
  3. 1 = color
  4. 2 = color, material
  5. 3 = color, material, size,
  6. 4 = color, material, size, position
  7. 5 = color, material, size, position, orientation
  8. 6 = color, material, size, position, orientation, velocity
  9. 7 = color, material, size, position^2, orientation, velocity
  10. (extras)
  11. 5.1 = color, material, size, position^2, orientation
  12. 5.2 = color, material, size, position, orientation, transparency
  13. ]]
  14. local levelofrandomization = 3
  15. local zoneofpositionpowertwo = 2048 --[[ the zone for position^2, used for randomization level 7]]
  16. local maxsize = 128 --[[max size for randomization, used for randomization level 3+]]
  17. local maxoffset = 128 -- [[max offset for randomization, used for randomization level 4+, 6-]]
  18. local maxdegree = 180 -- [[max angle for randomization, used for randomization level 5+]]
  19. local maxvelocity = 128 -- [[max velocity for randomization, used for randomization level 6+]]
  20. local offsetposition = false -- [[offset increase depends on size also, used for randomization level 4+, 6-]]
  21. local offsetsize = false -- [[offset of size adds/removes, instead of sets, used for randomization level 3+]]
  22. local offsetangle = false --[[offset of orientation adds/removes, instead of sets, used for randomization level 5+]]
  23. local offsetvelocity = false --[[offset of velocity adds/removes, instead of sets, used for randomization level 6+]]
  24. local lesslag = false --[[ use if theres like alot of parts in the map]]
  25. local old = false -- [[the old variation of this script, only checks for parts, and uses GetChildren instead]]
  26. local childaddedrandomize = false -- [[randomized the part when it gets added aswell]]
  27.  
  28. function randomizepart(obj)
  29.     if levelofrandomization >= 1 then
  30.         obj.Color = Color3.new(math.random(),math.random(),math.random())
  31.         if obj:IsA("UnionOperation") then
  32.             obj.UsePartColor = true
  33.         end
  34.     end
  35.     if levelofrandomization >= 2 then
  36.         obj.Material = Enum.Material:GetEnumItems()[math.random(1,#Enum.Material:GetEnumItems())]
  37.     end
  38.     if levelofrandomization >= 3 then
  39.         if offsetsize then
  40.             obj.Size = Vector3.new(obj.Size.X+math.random(-(obj.Size.X-1),maxsize),obj.Size.Y+math.random(-(obj.Size.Y-1),maxsize),obj.Size.Z+math.random(-(obj.Size.Z-1),maxsize))
  41.         else
  42.             obj.Size = Vector3.new(math.random(0.05,maxsize),math.random(0.05,maxsize),math.random(0.05,maxsize))
  43.         end
  44.     end
  45.     if levelofrandomization >= 4 then
  46.         if levelofrandomization ~= 7 then
  47.             if offsetposition then
  48.                 obj.Position = Vector3.new(obj.Position.X+obj.Position.X+math.random(-maxoffset,maxoffset),obj.Position.Y+obj.Position.Y+math.random(-maxoffset,maxoffset),obj.Position.Z+obj.Position.Z+math.random(-maxoffset,maxoffset))
  49.             else
  50.                 obj.Position = Vector3.new(obj.Position.X+math.random(-maxoffset,maxoffset),obj.Position.Y+math.random(-maxoffset,maxoffset),obj.Position.Z+math.random(-maxoffset,maxoffset))
  51.             end
  52.         else
  53.             obj.Position = Vector3.new(math.random(-zoneofpositionpowertwo,zoneofpositionpowertwo),math.random(-zoneofpositionpowertwo,zoneofpositionpowertwo),math.random(-zoneofpositionpowertwo,zoneofpositionpowertwo))
  54.         end
  55.     end
  56.     if levelofrandomization >= 5 then
  57.         if offsetangle then
  58.             obj.Orientation = Vector3.new(obj.Orientation.X+math.random(-maxdegree,maxdegree),obj.Orientation.Y+math.random(-maxdegree,maxdegree),obj.Orientation.Z+math.random(-maxdegree,maxdegree))
  59.         else
  60.             obj.Orientation = Vector3.new(math.random(-maxdegree,maxdegree),math.random(-maxdegree,maxdegree),math.random(-maxdegree,maxdegree))
  61.         end
  62.     end
  63.     if levelofrandomization >= 6 then
  64.         if offsetvelocity then
  65.             obj.Velocity = Vector3.new(obj.Velocity.X+math.random(-maxvelocity,maxvelocity),obj.Velocity.Y+math.random(-maxvelocity,maxvelocity),obj.Velocity.Z+math.random(-maxvelocity,maxvelocity))
  66.         else
  67.             obj.Velocity = Vector3.new(math.random(-maxvelocity,maxvelocity),math.random(-maxvelocity,maxvelocity),math.random(-maxvelocity,maxvelocity))
  68.         end
  69.     end
  70.     if levelofrandomization == 5.1 then
  71.         obj.Position = Vector3.new(math.random(-zoneofpositionpowertwo,zoneofpositionpowertwo),math.random(-zoneofpositionpowertwo,zoneofpositionpowertwo),math.random(-zoneofpositionpowertwo,zoneofpositionpowertwo))
  72.     end
  73.     if levelofrandomization == 5.2 then
  74.         obj.Transparency = math.random(0.0,0.9)
  75.     end
  76. end
  77.  
  78. if old then
  79.     for i,v in pairs(workspace:GetChildren()) do
  80.         if v:IsA("Part") then
  81.             randomizepart(v)
  82.         end
  83.         if lesslag then
  84.             game:GetService("RunService").Heartbeat:Wait()
  85.         end
  86.     end
  87. else
  88.     for i,v in pairs(workspace:GetDescendants()) do
  89.         if v:IsA("BasePart") then
  90.             randomizepart(v)
  91.         end
  92.         if lesslag then
  93.             game:GetService("RunService").Heartbeat:Wait()
  94.         end
  95.     end
  96. end
  97.  
  98. if childaddedrandomize then
  99.     workspace.ChildAdded:Connect(function(obj)
  100.         randomizepart(obj)
  101.     end)
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement