local collectedStages = {}
for i = 1, length do
while true do
wait()
local randSection = math.random(1, #sections)
local section = sections[randSection]:Clone()
if not collectedStages[i] then
local sectionY = section.Hitbox.Size.Y
section.Parent = game.Workspace.TowerSections
section.Name = i
if i % 2 == 0 then
section:SetPrimaryPartCFrame(CFrame.new(0, currentY + sectionY/2 , 0) * CFrame.Angles(0, math.rad(180), 0))
else
section:SetPrimaryPartCFrame(CFrame.new(0, currentY + sectionY/2, 0))
end
currentY += sectionY
section.Start.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local lvl = tonumber(section.Name)
if plr.TempStage.Value < lvl then
plr.TempStage.Value = lvl
collectedStages[lvl] = true
local coinsCalculation = ((plr.TempStage.Value - 1) * 3) + 5
local xpCalculation = ((plr.TempStage.Value - 1) * 2) + 5
plr.mainData.Coins.Value += coinsCalculation
plr.mainData.XP.Value += xpCalculation
end
end
end)
break
end
end
end
hitboxEnd.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.Character.HumanoidRootPart.Position.Y > (currentY - (finish.Hitbox.Size.Y / 2)) then
local lvl = tonumber(finish.Name)
if plr.TempStage.Value < lvl then
plr.TempStage.Value = lvl
plr.leaderstats.Wins.Value += 1
local coinsCalculation = ((plr.TempStage.Value - 1) * 3) + 10
local xpCalculation = ((plr.TempStage.Value - 1) * 2.5) + 10
plr.mainData.Coins.Value += coinsCalculation
plr.mainData.XP.Value += xpCalculation
end
end
end
end)