Greetings,
I have made a part spawning system for my simulator, though the limiter doesn’t work. maxparts
should’ve been the variable that was to stop and restart the system at a cap of 100 maximum parts. The Reset
event is whenever a player touches a spawned part. The script is a server script stored in server script service. The last part of the script seems to not work at all (When the Reset
event has to be received by the script). Please help! The script is attached down below
local RS = game:GetService("ReplicatedStorage")
local Reset = RS:WaitForChild("Adding"):WaitForChild("Speed")
local storage = game:GetService("ServerStorage").SpeedParts
local speed1 = storage:WaitForChild("1Speed")
local speed5 = storage:WaitForChild("5Speed")
local speed10 = storage:WaitForChild("10Speed")
local quarter1 = workspace.Quarter1
local quarter2 = workspace.Quarter2
local quarter3 = workspace.Quarter3
local quarter4 = workspace.Quarter4
local quarter5 = workspace.Quarter5
local maxparts = 0
local function partRegen()
while maxparts < 100 do
local partchance = math.random(1,10)
local chosenpart
if partchance <= 5 then
chosenpart = speed1
elseif partchance <= 8 and partchance > 5 then
chosenpart = speed5
elseif partchance <= 10 and partchance > 8 then
chosenpart = speed10
end
local quarter = math.random(1,5)
local chosenquarter
local pos1
local pos2
if quarter == 1 then
chosenquarter = quarter1
pos1 = math.random(-100,100)/100 * chosenquarter.Size.X/2
pos2 = math.random(-100,100)/100 * chosenquarter.Size.Z/2
elseif quarter == 2 then
chosenquarter = quarter2
pos1 = math.random(-100,100)/100 * chosenquarter.Size.X/2
pos2 = math.random(-100,100)/100 * chosenquarter.Size.Z/2
elseif quarter == 3 then
chosenquarter = quarter3
pos1 = math.random(-100,100)/100 * chosenquarter.Size.X/2
pos2 = math.random(-100,100)/100 * chosenquarter.Size.Z/2
elseif quarter == 4 then
chosenquarter = quarter4
pos1 = math.random(-100,100)/100 * chosenquarter.Size.X/2
pos2 = math.random(-100,100)/100 * chosenquarter.Size.Z/2
elseif quarter == 5 then
chosenquarter = quarter5
pos1 = math.random(-100,100)/100 * chosenquarter.Size.X/2
pos2 = math.random(-100,100)/100 * chosenquarter.Size.Z/2
end
local copypart = chosenpart:Clone()
copypart.Parent = workspace.SpeedParts
copypart.Position = chosenquarter.Position + Vector3.new(pos1, 1, pos2)
maxparts += 1
print("There are now: " ..maxparts)
wait(3.5)
end
end
partRegen()
Reset.Event:Connect(function()
maxparts -= 1
print("There are now: " ..maxparts)
partRegen()
end)