local function CheckMob()
for child = 1 , #mob do
if child < 20 then
local counter = newLoot:GetRandomLoot(1)
local newmob = game.ReplicatedStorage.Mob:FindFirstChild(counter)
if newmob then
local clone = newmob:Clone()
clone.Parent = game.Workspace.Map.Mob
clone.PrimaryPart.CFrame = CFrame.new(char.HumanoidRootPart.CFrame * Vector3.new(10,10,10))
print(counter)
else
return
end
else return end
end
end
As you can see at the script , the limit is 20 but for some reasons the script didn’t stop and crashing the game experiences . I did some research but I can’t find any solution so far . Any help here is appreciated . Let me know if you need anything.
still same or am I wrong . Here is the current script.
local function CheckMob()
if math.clamp(#mob , 1 , 20) then
local counter = newLoot:GetRandomLoot(1)
local newmob = game.ReplicatedStorage.Mob:FindFirstChild(counter)
if newmob then
local clone = newmob:Clone()
clone.Parent = game.Workspace.Map.Mob
clone.PrimaryPart.CFrame = CFrame.new(char.HumanoidRootPart.CFrame * Vector3.new(10,10,10))
print(counter)
end
end
end
since your code is pretty simple you just need to add this block of code and you’re done:
if on then return end
on= true
--code
on= false
local function CheckMob()
if on then return end
on= true
if math.clamp(#mob , 1 , 20) then
local counter = newLoot:GetRandomLoot(1)
local newmob = game.ReplicatedStorage.Mob:FindFirstChild(counter)
if newmob then
local clone = newmob:Clone()
clone.Parent = game.Workspace.Map.Mob
clone.PrimaryPart.CFrame = CFrame.new(char.HumanoidRootPart.CFrame * Vector3.new(10,10,10))
print(counter)
end
end
on= false
end
I mean Im trying to loop all children[mob] inside folder and check if the children is less than 20 I want to clone new until it hit 20 . but for some reasons it clone infinitly
it is exam, and It for programer.
Your code is incomplete, I don’t even know exactly how CheckMob is called.CheckMob() or by Event .
Can you answer it?
local function CheckMob()
for i=1, 20- #fd:getChildren() do
local counter = newLoot:GetRandomLoot(1)
local newmob = game.ReplicatedStorage.Mob:FindFirstChild(counter)
if newmob then
local clone = newmob:Clone()
clone.Parent = game.Workspace.Map.Mob
clone.PrimaryPart.CFrame = CFrame.new(char.HumanoidRootPart.CFrame * Vector3.new(10,10,10))
print(counter)
else
continue
end
end
end
fd is Folder contain mob!
I think here is what you want!