Stage loading script not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A script that loads stages for my project, based off of Tower Of Hell.

  2. What is the issue? Include screenshots / videos if possible!
    The script will not do anything, but also does not give any errors.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    None

Script:

local serverStorage = game:GetService("ServerStorage")

local repStorage = game:GetService("ReplicatedStorage")

local stagesStorage = serverStorage.Stages

local stagesList = stagesStorage:GetChildren()

local loadedStages = Instance.new("Folder")
loadedStages.Parent = workspace
loadedStages.Name = "Currently loaded stages"

local totalTimeValue = repStorage.TotalTime

local lengthValue = repStorage.TowerHeight

local function loadNewStages(length)
	for _, player in pairs(game.Players:GetPlayers()) do
		player.Character.HumanoidRootPart.CFrame = workspace.WorldSpawn.CFrame
	end
	loadedStages:ClearAllChildren()
	local previouslyLoadedCenter = workspace.Base
	for loaded = 0, length, 1 do
		local randomNumberChoice = math.random(#stagesList)
		local clonedStage = stagesList[randomNumberChoice]:Clone()
		clonedStage.Parent = loadedStages
		clonedStage.PrimaryPart = clonedStage.StageBase.Center
		local refrencePart = Instance.new("Part")
		refrencePart.Anchored = true
		refrencePart.Transparency = 1
		refrencePart.CanCollide = false
		refrencePart.Size = clonedStage.PrimaryPart.Size
		local yPos = (previouslyLoadedCenter.Size.Y/2)+(clonedStage.PrimaryPart.Size.Y/2)
		refrencePart.Position = Vector3.new(previouslyLoadedCenter.Position.X,yPos,previouslyLoadedCenter.Position.Z)
		refrencePart.Orientation = previouslyLoadedCenter.Orientation + 180
		clonedStage:SetPrimaryPartCFrame(refrencePart)
		refrencePart:Destroy()
	end
end

totalTimeValue:GetPropertyChangedSignal("Value"):Connect(function()
	if totalTimeValue.Value == 0 then
		totalTimeValue.Value = 450
		loadNewStages(lengthValue.Value)
	end
end)

When the game starts, (to start the loading) the TotalTime value switches from 450 (the round time in seconds), to 0.

Edit:

After running the game for some time, one error has appeared:
ServerScriptService.StageLoader:35: invalid argument #2 (Vector3 expected, got number)

1 Like

You are adding a number to a vector3 orientation, change the 180 to Vector3.new(180, 0, 0)

2 Likes

This will change it’s orientation by 180 degrees each time, correct?

1 Like

yes, orientation has 3 axis of rotation, so just adding 180 wouldn’t make sense

2 Likes

Okay, I added that line, but now the stages still do not appear.

1 Like

does it still show any errors?

1 Like

When the stages reload, it does give the error Unable to cast Instance to CoordinateFrame, which I think is an issue where I forgot to add .CFrame to the :SetPrimaryPartCFrame

1 Like

yea I was about to say that too, change to clonedStage:SetPrimaryPartCFrame(refrencePart.CFrame)

That seems to fix it. Now there is only one problem, which is that when I first load the game, the stages do not load until the first timer finishes.

Oh. And, the stages load inside of each other, and upside down.

1 Like

instead of
local totalTimeValue = repStorage.TotalTime
try
local totalTimeValue = 0

totalTimeValue is supposed to define the IntValue for the timer, not an integer.

1 Like

I think you can have a list of positions where the stages should go, and iterate through the list to spawn the stages at those locations. As for the upside down try changing orientation to (180, 180, 0)

1 Like
totalTimeValue:GetPropertyChangedSignal("Value"):Connect(function()
	if totalTimeValue.Value == 0 then
		totalTimeValue.Value = 450
		loadNewStages(lengthValue.Value)
	end
end)

either initialize the time value to 0 or call the function once when the server first loads

1 Like