I need help with my random obby game!

  1. What I want to achieve:
    I need to make a randomly generated obby like ‘Tower Of Hell’ but in a corridor format.
  2. The issue:
    My code simply won’t run. I tried putting the stages in replicated storage but it made no difference, so I moved the stages back to server storage which I think is safer.
  3. What I have you tried so far:
    I have tried putting the stages into replicated storage and server storage, which has made no difference and then I looked on the developer hub and I couldn’t find anything useful on there. So then I decided to create this post after re-writing my code 10+ times.

There are going to also be power ups as well, but in the code I named them mutators.

Code I have tried:

-- Services Variables --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

-- ServerStorage Variables --
local StageFolder = ServerStorage:WaitForChild("Stages")
local Stages = StageFolder:GetChildren()

-- Workspace Variables --
local Tower = game.Workspace:WaitForChild("Road")
local Storage = game.Workspace:WaitForChild("Storage")
local Lobby = Storage:WaitForChild("Lobby")
local End = Storage:WaitForChild("End")
local SpawnsModel = Lobby:WaitForChild("Spawns")
local Spawns = SpawnsModel:GetChildren()

-- Replicated Storage --
local TimerSpeed = ReplicatedStorage:WaitForChild("TimerSpeed")
local Minutes = ReplicatedStorage:WaitForChild("Minutes")
local Seconds = ReplicatedStorage:WaitForChild("Seconds")
local TimerTag = ReplicatedStorage:WaitForChild("TimerTag")
local MultiplierVisible = ReplicatedStorage:WaitForChild("MultiplierVisible")
local Multiplies = ReplicatedStorage:WaitForChild("Multiplies")
local TowerHeight = ReplicatedStorage:WaitForChild("TowerHeight")
local MutatorsFolder = ReplicatedStorage:WaitForChild("Mutators")

-- Main --
local Set1
local Set2

debounce = false

function NewTower()
	debounce = true
	
	-- Set 1 --
	Set1 = Stages[math.random(1, #Stages)]:Clone()
	Set1.Parent = Tower
	Set1.PrimaryPart = Set1:FindFirstChild("End")
	Set1:SetPrimaryPartCFrame(Set1.End.CFrame)
	local Set1Length = Set1.Length.Value
	
	-- Set 2 --
	wait()
	Set2 = Stages[math.random(1, #Stages)]:Clone()
	Set2.Parent = Tower
	Set2.PrimaryPart = Set2:FindFirstChild("End")
	Set2:SetPrimaryPartCFrame(Set1.End.CFrame)
	local Floor2Length = Set2.Length.Value
	
end

Minutes.Value = 5
Seconds.Value = 0
TimerSpeed.Value = 1
MultiplierVisible.Value = false
Multiplies.Value = 1
debounce = true
NewTower()

while true do
	if Minutes and Seconds and TimerSpeed and Tower and Stages then
		repeat
			if Seconds.Value <= 9 then
				TimerTag.Value = tostring(Minutes.Value)..":0"..tostring(Seconds.Value)
			else
				TimerTag.Value = tostring(Minutes.Value)..":"..tostring(Seconds.Value)
			end
			if Seconds.Value <= 0 then
				Minutes.Value = Minutes.Value - 1
				Seconds.Value = 59
			else
				Seconds.Value = Seconds.Value - 1
			end
			wait(TimerSpeed.Value)
		until Minutes.Value <= 0 and Seconds.Value <= 0
		if Minutes.Value <= 0 and Seconds.Value <= 0 then
			TimerTag.Value = "0:00"
		end
		wait(TimerSpeed.Value)
		for i, v in pairs(Players:GetChildren()) do
			if v.Character:FindFirstChild("Win") then
				v.Character.Win:Destroy()
			end
			if v:FindFirstChild("Backpack") then
				v.Backpack:ClearAllChildren()
			end
		end
		Tower:ClearAllChildren()
		Minutes.Value = 5
		Seconds.Value = 0
		TimerSpeed.Value = 1
		MultiplierVisible.Value = false
		Multiplies.Value = 1
		wait()
		NewTower()
		for i, v in pairs(Players:GetChildren()) do
			v.Character.Torso.CFrame = Spawns[math.random(1, #Spawns)].CFrame
		end
		for i, v in pairs(MutatorsFolder:GetChildren()) do
			v.Value = false
		end
	end
end

I am not asking for the script, I would just like a pointer in the right direction on where I went wrong and how I can fix it!

2 Likes

It would be very useful if you could put “print(“checkpoint x”)” or something like that to know where the code breaks

1 Like

But there’s no checkpoints? Is there somewhere in my script I could put that?

Its just a print. Put it anywhere. Check the output see where things got messy.

2 Likes

Maybe after each set of your code.

1 Like

Ok I will try now! Thanks! After each set of code right?

1 Like

Yep if you want. Or after anywhere. But for now do it after a set.

1 Like

It seems to print after every single line? And I don’t have any errors in output or the dev console?

1 Like

So you have no errors or are you having errors
.

1 Like

I am not having errors related to the script in question, I can send a screen shot of output if you like?

1 Like

What is the purpose of this line? You are taking the primary part (“End”), and setting it’s CFrame to itself. Therefore it won’t move at all.

1 Like

Oh ok, so I don’t need that line?

1 Like

Well it depends. I think that the model is cloning, but it probably isn’t being moved to the right location. Can you check the explorer to see if it does indeed clone it into the workspace?

1 Like

It does clone into workspace, so is it possible to CFrame each stage to be like one after the other?

Can you put an “End” part and a “Start” part inside each model. Then have a part in the workspace name “StartingPoint”. Make sure to capitalize the same as I did. Then do something like this:

function NewTower()
	debounce = true
	
	-- Set 1 --
	Set1 = Stages[math.random(1, #Stages)]:Clone()
	Set1.Parent = Tower
	Set1.PrimaryPart = Set1:FindFirstChild("Start")
	Set1:SetPrimaryPartCFrame(game.Workspace.StartingPoint.CFrame)
	local Set1Length = Set1.Length.Value
	
	-- Set 2 --
	wait()
	Set2 = Stages[math.random(1, #Stages)]:Clone()
	Set2.Parent = Tower
	Set2.PrimaryPart = Set2:FindFirstChild("Start")
	Set2:SetPrimaryPartCFrame(Set2.End.CFrame)
	local Floor2Length = Set2.Length.Value
	
end

Thank you so much, let me try it, then I will mark your post as solution!

1 Like

Thanks @XdJackyboiiXd21 it really helps! I will give you credit in the games credits Gui! Thanks again this helps so much!

1 Like

Glad I could help! :slight_smile: I can’t wait to play the game, it sounds very fun!

1 Like