#“Maximum event re-entrance depth exceeded for NumberValue.Changed”

4 messages · Page 1 of 1 (latest)

blazing moon
#

That text appears after loading 6 floors for this code:

local rep = game:GetService("ReplicatedStorage")
local FloorNum = rep.FloorNumber

local RoomsArray = rep.Rooms:GetChildren()
local ChosenRoom = nil

FloorNum.Changed:Connect(function(NewFloor)
if FloorNum.Value < 10 then
ChosenRoom = RoomsArray[math.random(1, #RoomsArray)]:Clone()
ChosenRoom.Parent = workspace.ChosenRooms
ChosenRoom.CFrame = CFrame.new(100, FloorNum.Value*5, 100)
FloorNum.Value += 1
end
end)

FloorNum.Value += 1

supple gulch
#

that happens bc you change the value within the changed function

#

the easiest way to solve is like this

local rep = game:GetService("ReplicatedStorage")
local FloorNum = rep.FloorNumber

local RoomsArray = rep.Rooms:GetChildren()
local ChosenRoom = nil

local debounce = false
FloorNum.Changed:Connect(function(NewFloor)
    if FloorNum.Value < 10 then
     if debounce then
        debounce = false
        return
      end
      ChosenRoom = RoomsArray[math.random(1, #RoomsArray)]:Clone()
      ChosenRoom.Parent = workspace.ChosenRooms
      ChosenRoom.CFrame = CFrame.new(100, FloorNum.Value*5, 100)
      FloorNum.Value += 1
      debounce = true
    end
end)

FloorNum.Value += 1
#

this should work out