Put the code below in a LocalScript. Run the project and run in-game somewhere away from center and press R on keyboard. Depending on your rig you will get ~1 sec freeze (fps drop to 1 orsmth). Is there any way to avoid it? I tough spawn (new thread) would be the rescue, but isn’t
local function addLotOfJunk()
local parts = 50000
local base = math.floor(parts ^(1/3))
local holder = Instance.new("Model")
local n = 0
for x = 1, base do
for z = 1, base do
for y = 1, math.ceil(parts/base^2) do
if n == parts then
break
end
local p = Instance.new("Part")
p.Anchored = true
p.Locked = true
p.CanCollide = true
p.Material = Enum.Material.SmoothPlastic
p.Size = Vector3.new(1,1,1)
local xx = x * 1
local yy = y * 1
local zz = z * 1
p.Position = Vector3.new(xx, yy, zz)
p.TopSurface = Enum.SurfaceType.Smooth
p.BottomSurface = Enum.SurfaceType.Smooth
p.Color = Color3.fromRGB(125, 125, 125)
local wedgeMesh = Instance.new("SpecialMesh", p)
wedgeMesh.MeshType = Enum.MeshType.Wedge
wedgeMesh.Scale = Vector3.new(0,1,1)
p.Parent = holder
n = n + 1
end
end
end
holder.Parent = workspace
end
local rPressed = false
local junkInitiated = false
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R and rPressed == false then
print("Adding junk in next step")
rPressed = true
end
end)
local RunService = game:GetService("RunService")
local function onStep(currentTime, deltaTime)
if rPressed == true and junkInitiated == false then
junkInitiated = true
print("Adding junk")
spawn(addLotOfJunk)
end
end
RunService.Stepped:Connect(onStep)