Hello! I made this terrain generation system but I’m having this issue where when I’m changing biomes in the terrain, it prints this twice, causing a noticable notch/variation in the terrain…
10:48:12.219 Change biomes! - Server - Terrain:108
10:48:12.219 Desert - Server - Terrain:111
10:48:12.300 Change biomes! - Server - Terrain:108
10:48:12.300 Mountains - Server - Terrain:111
Here’s the code, yes I tried doing a debounce but it doesn’t work.
local debounce = true
if x % BiomeSize == 0 and z % BiomeSize == 0 then -- In this example it will pause after each 100 loops
spawn(function()
if debounce == true then
debounce = false
print("Change biomes!")
PrintScaleFactor = true
currentBiome = Biomes[math.random(1, #Biomes)]
print(currentBiome)
wait(5)
ScaleFactor = false
debounce = true
end
end)
end
local x = true
local ScaleFactor = true
local PrintScaleFactor = false
local Biomes = {"aaa", "bbb", "ccc"}
local currentBiome = "abc"
------
local debounce = true
if x then -- In this example it will pause after each 100 loops
spawn(function()
if debounce == true then
debounce = false
print("Change biomes!")
PrintScaleFactor = true
currentBiome = Biomes[math.random(1, #Biomes)]
print(currentBiome)
wait(5)
ScaleFactor = false
debounce = true
end
end)
end
Only prints once … Somehow, you’re calling this more than once while x is still true.
The spawn(function() took the following wait() out of consideration to the rest of the program also.
if debounce == true then debounce = false
if x then -- In this example it will pause after each 100 loops
spawn(function()
print("Change biomes!")
PrintScaleFactor = true
currentBiome = Biomes[math.random(1, #Biomes)]
print(currentBiome)
wait(5)
ScaleFactor = false
debounce = true
end)
end
end
Maybe …depends on how this is called in the script.