Hello! my name is bullet, and today i’ve ran into another issue with my code…
This time, i was working on a generation system for a game, and we wanted to make it everytime you open a door instead of a loop, so i tried to implement that, and here’s how it went:
it generates once [ since the first door has no click detector ]
and then it generates again [ when you open the next rooms door ]
but then, it doesn’t generate or print ANYTHING at all the next room, aka " B-003 " is the last room it generates then it breaks.
Here’s the script:
local PastRoom
local CurrentRoom = game.Workspace.Rooms.StartRoom
local CurrentDoor
local FutureRoom
local RoomToClone
local RoomNumber1 = 0
local RoomNumber2 = 0
local RoomNumber3 = 1
local CaculNumber = 1
local CaculNumber2 = 1
function Generate()
RoomNumber3 += 1
CaculNumber += 1
CaculNumber2 += 1
if CaculNumber == 10 then
RoomNumber2 += 1
RoomNumber3 = 0
CaculNumber = 0
end
if CaculNumber2 == 100 then
RoomNumber1 += 1
RoomNumber2 = 0
RoomNumber3 = 0
CaculNumber2 = 0
CaculNumber = 0
end
local Rooms = game.ReplicatedStorage.Rooms:GetChildren()
local RandomNumber = math.random(1,#Rooms)
RoomToClone = Rooms[RandomNumber]
FutureRoom = RoomToClone:Clone()
FutureRoom:WaitForChild("Plate", 0.5).NumberGUI.Number.Text = "B-"..(RoomNumber1)..(RoomNumber2)..(RoomNumber3)
local PlacePoint = CurrentRoom:WaitForChild("PastPoint"):WaitForChild("PlacePoint")
FutureRoom:SetPrimaryPartCFrame(PlacePoint.CFrame)
task.wait()
FutureRoom.Parent = game.Workspace.GeneratedRooms
PastRoom = CurrentRoom
print(PastRoom)
task.wait()
CurrentRoom = FutureRoom
CurrentDoor = CurrentRoom:WaitForChild("Door")
print("loop")
end
Generate()
CurrentDoor.Hinge.Door.ClickDetector.MouseClick:Connect(function()
print("cool!")
Generate()
end)
If you want more details, ask in the comments.
Thanks for reading, and please help!