Hello there.
I am making this game which spawns enemies depending on your current biome.
I have region3 to check if a player is inside of a biome.
However, while testing, I noticed that my while true loop that keeps checking the player’s location stops at a random interval. Does while loops do that?
If this is an error, please point it out.
I copied the loop here.
while wait(4) do
print(“Check”)
biomeBlocks = game.Workspace.RegionParts:GetChildren()
local plrs = game.Players:GetChildren()
for plr = 1,#plrs,1 do
wait(0.2)
for i,v in pairs(biomeBlocks) do
wait(0.2)
local region = area[i]
local playersInRegion = game.Workspace:FindPartsInRegion3WithWhiteList(region,{plrs[plr].Character.HumanoidRootPart})
if playersInRegion[1] then
if playersInRegion[1].Parent == plrs[plr].Character then
plrs[plr].Stats.currentBiome.Value = v.Name
end
end
end
end
end
Sorry that the code doesn’t look optimized.
Thanks to those who respond.
*RegionParts is the parts in the workspace that marks the biomes.
while wait(4) do
print("Check")
biomeBlocks = game.Workspace.RegionParts:GetChildren()
local plrs = game.Players:GetChildren()
for plr = 1,#plrs,1 do
wait(0.2)
for i,v in pairs(biomeBlocks) do
wait(0.2)
local region = area[i]
local playersInRegion = game.Workspace:FindPartsInRegion3WithWhiteList(region,{plrs[plr].Character.HumanoidRootPart})
if playersInRegion[1] then
if playersInRegion[1].Parent == plrs[plr].Character then
plrs[plr].Stats.currentBiome.Value = v.Name
end
end
end
end
end
while wait() do
print("Check")
biomeBlocks = game.Workspace.RegionParts:GetChildren()
local plrs = game.Players:GetChildren()
for plr = 1,#plrs,1 do
for i,v in pairs(biomeBlocks) do
local region = area[i]
local playersInRegion = game.Workspace:FindPartsInRegion3WithWhiteList(region,{plrs[plr].Character.HumanoidRootPart})
if playersInRegion[1] then
if playersInRegion[1].Parent == plrs[plr].Character then
plrs[plr].Stats.currentBiome.Value = v.Name
end
end
end
end
end
Well you don’t really need that many wait, since you already have a wait in the while wait() do. Well as for your problem everything should work fine, the only reason I removed the wait is because it’s not needed.