Obby Race Minigame

Hello, im trying to make a Race Obby Minigame… The Objective is you have to gain the most depth while the obbies are generating randomly while going down, But im having an issue with the code.

Here’s the Issue:
image

Here’s My Code:

--// Game Serivces
local Lighting = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

--// Define Vars
local GameModes = {"Classic"}
local GameMode = nil
local SpawnPointMinigames = workspace:WaitForChild("GameValues").SpawnArea
local GameValues = workspace:WaitForChild( 'GameValues' )
local MinigameHolder = GameValues:WaitForChild( 'Minigames' )
local GameStorage = ServerStorage:WaitForChild( 'GameStorage' )
local PlayerNeeds = GameStorage:WaitForChild( 'PlayerStuff' )
local Maps = GameStorage:WaitForChild( 'Minigames' )
local RemoteEvent = Instance.new( 'RemoteEvent', ReplicatedStorage )
local RemoteFunction = Instance.new( 'RemoteFunction', ReplicatedStorage )
local RunService = game:GetService("RunService")
local DataStoreService = game:GetService("DataStoreService") --data store shit
local LeaderstatsDataStore = DataStoreService:GetDataStore("LeaderstatsDataStore")
--
local maxValue = -math.huge   --makes maxValue a insanely low number (-inf)
--
local StartingPos = GameValues.SpawnArea.Start.CFrame
local MaxObbies = 10
local DesignType = 'Classic'
local EndArea = nil
--
local Cache = {}
local PlayersInGame = {}
local LobbyPlayers = {}
local depthTable = {} --creating table that's going to contain and of the depths the player reaches
local Apis = {}
local Particles = {}
--
local Timer = 0
local Countdown = 4
local FallDamageHeight = 20
local Fix = false
--// Modules
local combat = require(script.Combat)

--// Preset
local part = Instance.new("Part")

--// Player Added
game.Players.PlayerAdded:Connect(function(player) --when player joins
	local leaderstats = Instance.new("Folder") --creating leaderstats
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local depth = Instance.new("IntValue") --creating Depth Value
	depth.Name = "Depth"
	depth.Parent = leaderstats

	local maxdepth = Instance.new("IntValue") --creating Max Depth Value
	maxdepth.Name = "Max Depth"
	maxdepth.Parent = leaderstats

	local playenamevalue = Instance.new("StringValue") --creating a string value that is the players name, so I can find character outside of playeradded event
	playenamevalue.Name = "PlayerNameValue"
	playenamevalue.Parent = player
	playenamevalue.Value = player.Name

	local leaderstats = player:WaitForChild("leaderstats")
	local maxdepth = leaderstats:WaitForChild("Max Depth")

	local data = LeaderstatsDataStore:GetAsync(player.UserId.."-Leaderstats")  

	if data == nil then
		maxdepth.Value = 0
	else
		maxdepth.Value = data["Max Depth"]

		local datanumber = Instance.new("IntValue")
		datanumber.Name = "datanumber"
		datanumber.Parent = player
		datanumber.Value = data["Max Depth"]
	end

	player.CharacterAdded:Connect(function(character)
		combat.Initialize(player)
		part.Parent = character:FindFirstChild("HumanoidRootPart")
		part.Anchored = true
		part.CanCollide = false
		part.CanQuery = false
		part.CanTouch = false
	end)
end)

--// Player Leaving
game.Players.PlayerRemoving:Connect(function(player)
	local maxdepth = player.leaderstats:FindFirstChild("Max Depth")
	local maxdepthvalue = maxdepth.Value
	local DataTable = {
		["Max Depth"] = maxdepthvalue
	}

	LeaderstatsDataStore:SetAsync(player.UserId.."-Leaderstats",DataTable)
	player.CharacterRemoving:Connect(function()
		part:Destroy()
	end)
end)

-- Extra
local Players = game:GetService("Players")
local playername = Players:FindFirstChild("PlayerNameValue", true)
local characterinworkspace = workspace:FindFirstChild(playername.Value) --variables for function below
local humanoid = characterinworkspace:FindFirstChild("Humanoid")
local Players = game:GetService("Players")
local datanumber = Players:FindFirstChild("datanumber", true)

--// Functions
function maxDepthRecorder() --records the depths the player reaches and inserts them into the depthTable
	for _, v in pairs(Players:GetPlayers()) do
		local depth = Players:FindFirstChild("Depth", true)
		local maxdepth = Players:FindFirstChild("Max Depth", true)
		table.insert(depthTable, depth.Value)
	end
end

function maxDepthUpdater() --updates Max Depth value
	local depth = Players:FindFirstChild("Depth", true)
	local leaderstats = Players:FindFirstChild("leaderstats", true)
	local maxdepth = Players:FindFirstChild("Max Depth", true)
	for _, v in ipairs(depthTable) do
		if depth.Value > maxValue and depth.Value > datanumber.Value then --if depth value is greater than the max value then max value is EQUAL to depth value and max depth value is EQUAL to max value
			maxValue = depth.Value
			maxdepth.Value = maxValue


		end
	end
end

function LevelManager(Data)
	if Data.LevelData.CurrentXP.Value >= Data.LevelData.NeededXP.Value then
		Data.LevelData.Level.Value = Data.LevelData.Level.Value + 1
		Data.LevelData.NeededXP.Value = Data.LevelData.NeededXP.Value * 1.5
		Data.LevelData.CurrentXP.Value = 0
		Data.Currencies.Coins.Value = Data.Currencies.Coins.Value + 400

		local Plr = game.Players:FindFirstChild(Data.Name)
		if Plr then
			RemoteEvent:FireClient({ 'Level', 'UpLvl', Plr })
		end
	end
end

function AddXP(PlrName, Amount)
	local Data = GetData(PlrName)
	local Mul = 1
	if Data then
		if Data.GamePasses.Premium.Value then
			Mul = 2
		end
		Data.LevelData.CurrentXP.Value = Data.LevelData.CurrentXP.Value + Amount * Mul
		LevelManager(Data)
	end
end

function SpawnCoins(Plate)
	for i = 1,4 do
		local Val = 100
		local Coin = ServerStorage.GameStorage.Extra.Coin:Clone()
		Coin.Parent = workspace:WaitForChild('GameValues').Currneyc.Coins
		Coin.CFrame = Plate.CFrame*CFrame.new(Random.new():NextInteger(-Plate.Size.X/2,Plate.Size.X/2),0,Random.new():NextInteger(-Plate.Size.Z/2,Plate.Size.Z/2))
		local x = Random.new():NextInteger(1,5)
		--[[if x == 5 then
			coin.BrickColor = BrickColor.new("Cyan")
			val = 4
		end]]

		game.Debris:AddItem(Coin,20)
		local conn
		
		conn = Coin.Touched:Connect(function(prt)
			if prt and prt.Parent == nil then return end
			local h = prt.Parent:FindFirstChild("Humanoid")
			if h then
				--// Add Data Stuff
				Coin:Destroy()
				conn:Disconnect()
			end
		end)
	end
end

local function PlayParticles()
	for i=1, #Particles do
		Particles[i].Enabled = true
		task.wait(1)
		Particles[i].Enabled = false
		task.wait()
		table.clear(Particles)
	end
end


function GetData(PlrName)

end

function DepthCounter()
	
end

function TopDepthUpdate(plr)
	
end

function MakePeopleInvisibleNear(Toggle)
	
end

function SetupRound()
	MinigameHolder:ClearAllChildren()
	PlayersInGame = {}
	LobbyPlayers = {}
		--[[
	local SpecialRoundOdds = math.random(1,100)
	if SpecialRoundOdds <= 10 then
		-- Special Round
		local SelectedMode = nil
		while true do
			local Mode = GameModes[math.random(1, #GameModes)]
			if Mode ~= GameModes[ 'Classic' ] then
				SelectedMode = Mode
				break
			end
		end
	else
		-- Classic Round
		GameMode = GameModes[1]
	end
	]]
	GameMode = GameModes[1]
	RemoteEvent:FireAllClients({ 'Intermission', 'Display', 'The Game Mode Is '..GameMode..'!', 3})
	wait(3)
	RemoteEvent:FireAllClients({ 'Intermission', 'Hide' })
	
	--// Generate Obbies
	local SpawnObby = ServerStorage.GameStorage.Minigames.SpawnStage.SpawnStage:Clone()
	SpawnObby.Parent = GameValues.Minigames
	RemoteEvent:FireAllClients({ 'Intermission', 'Display', 'Loading Map..',3 })
	wait(3)
	local Start = GameValues.Minigames:WaitForChild('SpawnStage').SpawnPart
	for i = 1,MaxObbies do
		local NewObby = ServerStorage.GameStorage.Minigames.Obbies:GetChildren()[math.random(#ServerStorage.GameStorage.Minigames.Obbies:GetChildren())]:Clone()
		NewObby.Parent = GameValues.Minigames
		NewObby:SetPrimaryPartCFrame(Start.CFrame)
		Start = NewObby.End
	end
	RemoteEvent:FireAllClients({ 'Intermission', 'Hide' })
end

function SpawnPlayers()
	if GameMode == 'Classic' then
		-- Get Players And Put Them Into Table
		local Players = game.Players:GetPlayers()
		for i,v in pairs(Players) do
			local Tag = Instance.new( 'BoolValue', v.Character )
			Tag.Name = 'Alive'
			Tag.Value = true
			table.insert(PlayersInGame, v)
		end
		
		-- Spawn Players
		local Spawn = SpawnPointMinigames.Start
		for i,v in pairs(PlayersInGame) do
			if v.Character and v.Character:FindFirstChild('HumanoidRootPart') and v.Character:FindFirstChild( 'Humanoid' ) and v.Character.Humanoid.Health > 0 then
				local UpperTorso = v.Character.HumanoidRootPart
				UpperTorso.CFrame = CFrame.new(Spawn.Position.X, Spawn.Position.Y + 3, Spawn.Position.Z)
				RemoteEvent:FireAllClients({ 'Camera Management', 'End', 'Specific Player', v })
				wait(0.25)
			end
		end
		repeat
			workspace.GameValues.Sounds.GiveSound:Play()
			Countdown = Countdown - 1
			RemoteEvent:FireAllClients({'Countdown', 'Display', Countdown})
			wait(1)
		until Countdown <= 1
		RemoteEvent:FireAllClients({'Countdown', 'Hide', Countdown})
		RemoteEvent:FireAllClients({ 'Intermission', 'Display', 'GOOD LUCK!', 3})
		wait(3)
		RemoteEvent:FireAllClients({ 'Intermission', 'Hide' })
	end
end

function BeforeRound(Toggle)
	RemoteEvent:FireAllClients({ 'Camera Management', 'Begin', 'Everyone', GameValues.ViewBrick.CameraOne })
	wait(1.5)
	if Toggle == 'Begin' then
	
	elseif Toggle == 'End' then
		
	end
end

function FallDamageCheck(player)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")
	local rootPart = character:FindFirstChild("HumanoidRootPart")
	if humanoid and rootPart then
		local highestPart = rootPart.Position.y - character:GetExtentsSize().y / 2
		local fallHeight = highestPart - character.PrimaryPart.Position.y

		if fallHeight >= FallDamageHeight then
			local fallDamage = (fallHeight - FallDamageHeight) / 10
			humanoid:TakeDamage(fallDamage)
		end
	elseif not character then
		return
	end
end

function CalculateDepth(player)
	local referencePoint = GameValues.SpawnArea.Start.Position
	local currentDepth = math.floor((player.Character.HumanoidRootPart.Position.Y - referencePoint.Y) / 5)
	return currentDepth
end

local function CheckPlayerPosition(Part)
	
end

function LaunchRound()
	print(GameMode)
	local Winner = nil
	local highestDepth = 0
	local LastRaycast
	local Params = RaycastParams.new()
	Params.FilterDescendantsInstances = {game.Workspace.GameValues.Minigames:GetChildren()}
	Params.FilterType = Enum.RaycastFilterType.Include
	local FiredOnce = false
	local RaycastResult
	local RayOrigin = Vector3.new()
	local RayDireciton = Vector3.new(0,-5.5,0)
	
	if GameMode == 'Classic' then
		SpawnPlayers()
		local playerDepths = {}
		for _, player in ipairs(game.Players:GetPlayers()) do
			playerDepths[player] = 0
		end
		wait(1)
		local Timer = 60 * 2
		repeat
			Timer = Timer - 1
			RemoteEvent:FireAllClients({ 'Timer', 'Display', Timer })
			GameValues.Settings.Timer.Value = Timer
			wait(1)
			local PlayersAlive = false
			for _, v in pairs(game.Players:GetPlayers()) do
				if v and v.Character and v.Character:FindFirstChild('Humanoid') and v.Character.Humanoid.Health > 0 and v.Character:FindFirstChild('Alive') then
					PlayersAlive = true
				end
			end
			for i, v in pairs(workspace.GameValues.Minigames:GetDescendants()) do
				if v.Name == "GlowPart" then
					v.Touched:Connect(function(hit)
						if hit.Parent:FindFirstChild("Humanoid") then
							v.Material = Enum.Material.Neon
						end
					end)
					v.TouchEnded:Connect(function(hit)
						if hit.Parent:FindFirstChild("Humanoid") then
							v.Material = Enum.Material.Metal
						end
					end)
				elseif v.Name == "SpinPart" then
					local Info = TweenInfo.new(
						50,
						Enum.EasingStyle.Sine,
						Enum.EasingDirection.Out,
						math.huge,
						false,
						0
					)
					local TweenService = game:GetService("TweenService")
					local Tween = TweenService:Create(v, Info, { CFrame = v.CFrame * CFrame.Angles(0, math.rad(90), 0) })
					Tween:Play()
					CheckPlayerPosition(v)
				elseif v.Name == "WackyPlatform" then
					local info = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, -1, true)
					local TweenService = game:GetService("TweenService")
					local tween = TweenService:Create(v, info, {CFrame = v.CFrame * CFrame.new(0, 0, -10)})

					tween:Play()

					local LastPosition = v.Position


					RunService.Stepped:Connect(function (_, deltatime)
						local currentPosition = v.Position
						local deltaPosition = currentPosition - LastPosition
					end)
				end
			end
			
			for i,v in pairs(game.Players:GetPlayers()) do
				part.Position = v.Character:FindFirstChild("HumanoidRootPart").Position
				part.Orientation = v.Character:FindFirstChild("HumanoidRootPart").Orientation
				RayOrigin = part.Position
				RaycastResult = workspace:Raycast(RayOrigin, RayDireciton, Params)
				if not RaycastResult then
					if LastRaycast then
						if LastRaycast.Name == "HealPart" then LastRaycast = nil FiredOnce = false return end
						LastRaycast.Material = Enum.Material.Metal
						LastRaycast = nil
						FiredOnce = false
					end
					return
				end
				if RaycastResult then
					if FiredOnce then return end
					LastRaycast = RaycastResult.Instance
					print("Instance", RaycastResult.Instance)
					print("Position", RaycastResult.Position)
					print("Distance", RaycastResult.Distance)
					if LastRaycast.Name == "GlowPart" then
						LastRaycast.Material = Enum.Material.Neon
						LastRaycast.PlatformSound:Play()
						FiredOnce = true
						return
					elseif LastRaycast.Name == "WackyPlatform" then
						LastRaycast.Material = Enum.Material.Neon
						LastRaycast.WackyPlatformSound:Play()
						FiredOnce = true
						return
					elseif LastRaycast.Name == "HealPart" then
						if LastRaycast.Material == Enum.Material.Neon then return end
						for _, particles in pairs(LastRaycast:GetChildren()) do
							if particles.ClassName == "ParticleEmitter" then table.insert(Particles, particles) end
						end
						LastRaycast.Color = Color3.fromRGB(0, 255, 0)
						LastRaycast.Material = Enum.Material.Neon
						LastRaycast.CheckpointSound:Play()
						FiredOnce = true
						task.spawn(PlayParticles)
						return
					end
				end
			end
			
			maxDepthRecorder()
			task.wait()
			print("Updating max depth")
			maxDepthUpdater()
			--// Determine Winner Either Depth Or Who Ever Finishes First
		until Timer <= 0
		for player, depth in pairs(playerDepths) do
			if depth > highestDepth then
				highestDepth = depth
				Winner = player
			end
		end
	end

	RemoteEvent:FireAllClients({ 'Timer', 'Hide' })

	local players = game.Players:GetPlayers()

	for _, v in pairs(game.Players:GetPlayers()) do
		if v and v.Character and v.Character:FindFirstChild('Humanoid') and v.Character.Humanoid.Health > 0 and v.Character:FindFirstChild('Alive') then
			v:LoadCharacter()
		end
	end

	if Winner then
		RemoteEvent:FireAllClients({ "Intermission", "Display", Winner.Name .. " wins with a depth of " .. highestDepth .. " studs!", 5 })
	else
		RemoteEvent:FireAllClients({ "Intermission", "Display", "No winner this time!", 5 })
	end
	wait(5)
	Fix = true
end

--// RemoteEvent Manager
RemoteEvent.OnServerEvent:Connect(function(Player, Input)
	if Input[1] == "M1" then
		local index = combat._records[Player]
		index:M1()
	end
end)

--// RemoteFunction Manager
RemoteFunction.OnServerInvoke = function(Player, Input)
	
end

--// Loop
while true do
	local PlayerCount = #game.Players:GetPlayers()
	if PlayerCount >= 1 then
		Timer = 30
		RemoteEvent:FireAllClients({ 'Intermission', 'Display', 'Intermission',30})
		repeat
			Timer = Timer -1
			GameValues.Settings.Timer.Value = Timer
			RemoteEvent:FireAllClients({ 'Timer', 'Display', Timer})
			wait(1)
		until Timer <= 0
		wait(1)
		RemoteEvent:FireAllClients({ 'Timer', 'Hide'})
		RemoteEvent:FireAllClients({ 'Intermission', 'Hide' })
		Timer = 50*4
		Fix = false
		SetupRound()
		LaunchRound()
		repeat wait() until Fix
	else
		--local coinD = GameValues.Currneyc.CoinSpawner
		--if coinD then
			--SpawnCoins(coinD)
		--end
		RemoteEvent:FireAllClients({ 'Intermission', 'Display', '2 Players Needed('..#game.Players:GetPlayers()..')!',5})
	end
	wait(5)
end
1 Like

im sorry in advanced for the messy code, still havent found a format

1 Like

This is whats causing your error. You are looking for an object called “PlayerNameValue” inside the actual Players service → It returns nil (cause it doesn’t exist) → then when you do workspace:FindFirstChild(playername.Value), you are basically doing the same thing as workspace:FindFirstChild(nil.Value). So the error is saying you are trying to reference “Value” on nil/nothing.

1 Like

Okay, how would I fix it… I’ve tried everything

1 Like

Well, what is the “PlayerNameValue” that’s supposed to be in Players mean’t for?

I updated the code

--// Game Serivces
local Lighting = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

--// Define Vars
local GameModes = {"Classic"}
local GameMode = nil
local SpawnPointMinigames = workspace:WaitForChild("GameValues").SpawnArea
local GameValues = workspace:WaitForChild( 'GameValues' )
local MinigameHolder = GameValues:WaitForChild( 'Minigames' )
local GameStorage = ServerStorage:WaitForChild( 'GameStorage' )
local PlayerNeeds = GameStorage:WaitForChild( 'PlayerStuff' )
local Maps = GameStorage:WaitForChild( 'Minigames' )
local RemoteEvent = Instance.new( 'RemoteEvent', ReplicatedStorage )
local RemoteFunction = Instance.new( 'RemoteFunction', ReplicatedStorage )
local RunService = game:GetService("RunService")
local DataStoreService = game:GetService("DataStoreService") --data store shit
local LeaderstatsDataStore = DataStoreService:GetDataStore("LeaderstatsDataStore")
--
local maxValue = -math.huge   --makes maxValue a insanely low number (-inf)
--
local StartingPos = GameValues.SpawnArea.Start.CFrame
local MaxObbies = 10
local DesignType = 'Classic'
local EndArea = nil
--
local Cache = {}
local PlayersInGame = {}
local LobbyPlayers = {}
local depthTable = {} --creating table that's going to contain and of the depths the player reaches
local Apis = {}
local Particles = {}
--
local Timer = 0
local Countdown = 4
local FallDamageHeight = 20
local Fix = false
--// Modules
local combat = require(script.Combat)
local fallingSoundInstance = require(script.FallingSound)
local platformHandler = require(script.PlatformHandler)

--// Preset
local part = Instance.new("Part")

--// Player Added
game.Players.PlayerAdded:Connect(function(player) --when player joins
	local leaderstats = Instance.new("Folder") --creating leaderstats
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local depth = Instance.new("IntValue") --creating Depth Value
	depth.Name = "Depth"
	depth.Parent = leaderstats

	local maxdepth = Instance.new("IntValue") --creating Max Depth Value
	maxdepth.Name = "Max Depth"
	maxdepth.Parent = leaderstats

	local playenamevalue = Instance.new("StringValue") --creating a string value that is the players name, so I can find character outside of playeradded event
	playenamevalue.Name = "PlayerNameValue"
	playenamevalue.Parent = player
	playenamevalue.Value = player.Name

	local leaderstats = player:WaitForChild("leaderstats")
	local maxdepth = leaderstats:WaitForChild("Max Depth")

	local data = LeaderstatsDataStore:GetAsync(player.UserId.."-Leaderstats")  

	if data == nil then
		maxdepth.Value = 0
	else
		maxdepth.Value = data["Max Depth"]

		local datanumber = Instance.new("IntValue")
		datanumber.Name = "datanumber"
		datanumber.Parent = player
		datanumber.Value = data["Max Depth"]
	end

	player.CharacterAdded:Connect(function(character)
		fallingSoundInstance.new()
		fallingSoundInstance:Start()
		combat.Initialize(player)
		part.Parent = character:FindFirstChild("HumanoidRootPart")
		part.Anchored = true
		part.CanCollide = false
		part.CanQuery = false
		part.CanTouch = false
	end)
end)

--// Player Leaving
game.Players.PlayerRemoving:Connect(function(player)
	local maxdepth = player.leaderstats:FindFirstChild("Max Depth")
	local maxdepthvalue = maxdepth.Value
	local DataTable = {
		["Max Depth"] = maxdepthvalue
	}

	LeaderstatsDataStore:SetAsync(player.UserId.."-Leaderstats",DataTable)
	player.CharacterRemoving:Connect(function()
		part:Destroy()
	end)
end)



--// Functions
function maxDepthRecorder() --records the depths the player reaches and inserts them into the depthTable
	for _, v in pairs(game.Players:GetPlayers()) do
		local depth = v:FindFirstChild("Depth", true)
		local maxdepth = v:FindFirstChild("Max Depth", true)
		table.insert(depthTable, depth.Value)
	end
end

function maxDepthUpdater() --updates Max Depth value
	for i,v in pairs(game.Players:GetPlayers()) do
		local depth = v:FindFirstChild("Depth", true)
		local leaderstats = v:FindFirstChild("leaderstats", true)
		local maxdepth = v:FindFirstChild("Max Depth", true)
		for _, v in ipairs(depthTable) do
			if depth.Value > maxValue and depth.Value > v:FindFirastChild('datanumber').Value then --if depth value is greater than the max value then max value is EQUAL to depth value and max depth value is EQUAL to max value
				maxValue = depth.Value
				maxdepth.Value = maxValue


			end
		end
	end
end

function LevelManager(Data)
	if Data.LevelData.CurrentXP.Value >= Data.LevelData.NeededXP.Value then
		Data.LevelData.Level.Value = Data.LevelData.Level.Value + 1
		Data.LevelData.NeededXP.Value = Data.LevelData.NeededXP.Value * 1.5
		Data.LevelData.CurrentXP.Value = 0
		Data.Currencies.Coins.Value = Data.Currencies.Coins.Value + 400

		local Plr = game.Players:FindFirstChild(Data.Name)
		if Plr then
			RemoteEvent:FireClient({ 'Level', 'UpLvl', Plr })
		end
	end
end

function AddXP(PlrName, Amount)
	local Data = GetData(PlrName)
	local Mul = 1
	if Data then
		if Data.GamePasses.Premium.Value then
			Mul = 2
		end
		Data.LevelData.CurrentXP.Value = Data.LevelData.CurrentXP.Value + Amount * Mul
		LevelManager(Data)
	end
end

function SpawnCoins(Plate)
	for i = 1,4 do
		local Val = 100
		local Coin = ServerStorage.GameStorage.Extra.Coin:Clone()
		Coin.Parent = workspace:WaitForChild('GameValues').Currneyc.Coins
		Coin.CFrame = Plate.CFrame*CFrame.new(Random.new():NextInteger(-Plate.Size.X/2,Plate.Size.X/2),0,Random.new():NextInteger(-Plate.Size.Z/2,Plate.Size.Z/2))
		local x = Random.new():NextInteger(1,5)
		--[[if x == 5 then
			coin.BrickColor = BrickColor.new("Cyan")
			val = 4
		end]]

		game.Debris:AddItem(Coin,20)
		local conn
		
		conn = Coin.Touched:Connect(function(prt)
			if prt and prt.Parent == nil then return end
			local h = prt.Parent:FindFirstChild("Humanoid")
			if h then
				--// Add Data Stuff
				Coin:Destroy()
				conn:Disconnect()
			end
		end)
	end
end

local function PlayParticles()
	for i=1, #Particles do
		Particles[i].Enabled = true
		task.wait(1)
		Particles[i].Enabled = false
		task.wait()
		table.clear(Particles)
	end
end


function GetData(PlrName)

end

function DepthCounter()
	
end

function TopDepthUpdate(plr)
	
end

function MakePeopleInvisibleNear(Toggle)
	
end

function SetupRound()
	MinigameHolder:ClearAllChildren()
	PlayersInGame = {}
	LobbyPlayers = {}
		--[[
	local SpecialRoundOdds = math.random(1,100)
	if SpecialRoundOdds <= 10 then
		-- Special Round
		local SelectedMode = nil
		while true do
			local Mode = GameModes[math.random(1, #GameModes)]
			if Mode ~= GameModes[ 'Classic' ] then
				SelectedMode = Mode
				break
			end
		end
	else
		-- Classic Round
		GameMode = GameModes[1]
	end
	]]
	GameMode = GameModes[1]
	RemoteEvent:FireAllClients({ 'Intermission', 'Display', 'The Game Mode Is '..GameMode..'!', 3})
	wait(3)
	RemoteEvent:FireAllClients({ 'Intermission', 'Hide' })
	
	--// Generate Obbies
	local SpawnObby = ServerStorage.GameStorage.Minigames.SpawnStage.SpawnStage:Clone()
	SpawnObby.Parent = GameValues.Minigames
	RemoteEvent:FireAllClients({ 'Intermission', 'Display', 'Loading Map..',3 })
	wait(3)
	local Start = GameValues.Minigames:WaitForChild('SpawnStage').SpawnPart
	for i = 1,MaxObbies do
		local NewObby = ServerStorage.GameStorage.Minigames.Obbies:GetChildren()[math.random(#ServerStorage.GameStorage.Minigames.Obbies:GetChildren())]:Clone()
		NewObby.Parent = GameValues.Minigames
		NewObby:SetPrimaryPartCFrame(Start.CFrame)
		Start = NewObby.End
	end
	RemoteEvent:FireAllClients({ 'Intermission', 'Hide' })
end

function SpawnPlayers()
	if GameMode == 'Classic' then
		-- Get Players And Put Them Into Table
		local Players = game.Players:GetPlayers()
		for i,v in pairs(Players) do
			local Tag = Instance.new( 'BoolValue', v.Character )
			Tag.Name = 'Alive'
			Tag.Value = true
			table.insert(PlayersInGame, v)
		end
		
		-- Spawn Players
		local Spawn = SpawnPointMinigames.Start
		for i,v in pairs(PlayersInGame) do
			if v.Character and v.Character:FindFirstChild('HumanoidRootPart') and v.Character:FindFirstChild( 'Humanoid' ) and v.Character.Humanoid.Health > 0 then
				local UpperTorso = v.Character.HumanoidRootPart
				UpperTorso.CFrame = CFrame.new(Spawn.Position.X, Spawn.Position.Y + 3, Spawn.Position.Z)
				RemoteEvent:FireAllClients({ 'Camera Management', 'End', 'Specific Player', v })
				wait(0.25)
			end
		end
		repeat
			workspace.GameValues.Sounds.GiveSound:Play()
			Countdown = Countdown - 1
			RemoteEvent:FireAllClients({'Countdown', 'Display', Countdown})
			wait(1)
		until Countdown <= 1
		RemoteEvent:FireAllClients({'Countdown', 'Hide', Countdown})
		RemoteEvent:FireAllClients({ 'Intermission', 'Display', 'GOOD LUCK!', 3})
		wait(3)
		RemoteEvent:FireAllClients({ 'Intermission', 'Hide' })
	end
end

function BeforeRound(Toggle)
	RemoteEvent:FireAllClients({ 'Camera Management', 'Begin', 'Everyone', GameValues.ViewBrick.CameraOne })
	wait(1.5)
	if Toggle == 'Begin' then
	
	elseif Toggle == 'End' then
		
	end
end

function FallDamageCheck(player)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")
	local rootPart = character:FindFirstChild("HumanoidRootPart")
	if humanoid and rootPart then
		local highestPart = rootPart.Position.y - character:GetExtentsSize().y / 2
		local fallHeight = highestPart - character.PrimaryPart.Position.y

		if fallHeight >= FallDamageHeight then
			local fallDamage = (fallHeight - FallDamageHeight) / 10
			humanoid:TakeDamage(fallDamage)
		end
	elseif not character then
		return
	end
end

function CalculateDepth(player)
	local referencePoint = GameValues.SpawnArea.Start.Position
	local currentDepth = math.floor((player.Character.HumanoidRootPart.Position.Y - referencePoint.Y) / 5)
	return currentDepth
end

local function CheckPlayerPosition(Part)
	
end

function LaunchRound()
	print(GameMode)
	local Winner = nil
	local highestDepth = 0
	local LastRaycast
	local Params = RaycastParams.new()
	Params.FilterDescendantsInstances = {game.Workspace.GameValues.Minigames:GetChildren()}
	Params.FilterType = Enum.RaycastFilterType.Include
	local FiredOnce = false
	local RaycastResult
	local RayOrigin = Vector3.new()
	local RayDireciton = Vector3.new(0,-5.5,0)
	
	if GameMode == 'Classic' then
		SpawnPlayers()
		local playerDepths = {}
		for _, player in ipairs(game.Players:GetPlayers()) do
			playerDepths[player] = 0
		end
		wait(1)
		local Timer = 60 * 2
		repeat
			Timer = Timer - 1
			RemoteEvent:FireAllClients({ 'Timer', 'Display', Timer })
			GameValues.Settings.Timer.Value = Timer
			wait(1)
			local PlayersAlive = false
			for _, v in pairs(game.Players:GetPlayers()) do
				if v and v.Character and v.Character:FindFirstChild('Humanoid') and v.Character.Humanoid.Health > 0 and v.Character:FindFirstChild('Alive') then
					PlayersAlive = true
				end
			end
			for i, v in pairs(workspace.GameValues.Minigames:GetDescendants()) do
				if v.Name == "GlowPart" then
					v.Touched:Connect(function(hit)
						if hit.Parent:FindFirstChild("Humanoid") then
							v.Material = Enum.Material.Neon
						end
					end)
					v.TouchEnded:Connect(function(hit)
						if hit.Parent:FindFirstChild("Humanoid") then
							v.Material = Enum.Material.Metal
						end
					end)
				elseif v.Name == "SpinPart" then
					local Info = TweenInfo.new(
						50,
						Enum.EasingStyle.Sine,
						Enum.EasingDirection.Out,
						math.huge,
						false,
						0
					)
					local TweenService = game:GetService("TweenService")
					local Tween = TweenService:Create(v, Info, { CFrame = v.CFrame * CFrame.Angles(0, math.rad(90), 0) })
					Tween:Play()
					CheckPlayerPosition(v)
				elseif v.Name == "WackyPlatform" then
					local info = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, -1, true)
					local TweenService = game:GetService("TweenService")
					local tween = TweenService:Create(v, info, {CFrame = v.CFrame * CFrame.new(0, 0, -10)})

					tween:Play()

					local LastPosition = v.Position


					RunService.Stepped:Connect(function (_, deltatime)
						local currentPosition = v.Position
						local deltaPosition = currentPosition - LastPosition
					end)
				end
			end
			
			for i,v in pairs(game.Players:GetPlayers()) do
				part.Position = v.Character:FindFirstChild("HumanoidRootPart").Position
				part.Orientation = v.Character:FindFirstChild("HumanoidRootPart").Orientation
				RayOrigin = part.Position
				RaycastResult = workspace:Raycast(RayOrigin, RayDireciton, Params)
				if not RaycastResult then
					if LastRaycast then
						if LastRaycast.Name == "HealPart" then LastRaycast = nil FiredOnce = false return end
						LastRaycast.Material = Enum.Material.Metal
						LastRaycast = nil
						FiredOnce = false
					end
					return
				end
				if RaycastResult then
					if FiredOnce then return end
					LastRaycast = RaycastResult.Instance
					print("Instance", RaycastResult.Instance)
					print("Position", RaycastResult.Position)
					print("Distance", RaycastResult.Distance)
					if LastRaycast.Name == "GlowPart" then
						LastRaycast.Material = Enum.Material.Neon
						LastRaycast.PlatformSound:Play()
						FiredOnce = true
						return
					elseif LastRaycast.Name == "WackyPlatform" then
						LastRaycast.Material = Enum.Material.Neon
						LastRaycast.WackyPlatformSound:Play()
						FiredOnce = true
						return
					elseif LastRaycast.Name == "HealPart" then
						if LastRaycast.Material == Enum.Material.Neon then return end
						for _, particles in pairs(LastRaycast:GetChildren()) do
							if particles.ClassName == "ParticleEmitter" then table.insert(Particles, particles) end
						end
						LastRaycast.Color = Color3.fromRGB(0, 255, 0)
						LastRaycast.Material = Enum.Material.Neon
						LastRaycast.CheckpointSound:Play()
						FiredOnce = true
						task.spawn(PlayParticles)
						return
					end
				end
			end
			platformHandler.new()
			platformHandler:ConnectTouchEvents()
			maxDepthRecorder()
			task.wait()
			print("Updating max depth")
			maxDepthUpdater()
			--// Determine Winner Either Depth Or Who Ever Finishes First
		until Timer <= 0
		for player, depth in pairs(playerDepths) do
			if depth > highestDepth then
				highestDepth = depth
				Winner = player
			end
		end
	end

	RemoteEvent:FireAllClients({ 'Timer', 'Hide' })

	local players = game.Players:GetPlayers()

	for _, v in pairs(game.Players:GetPlayers()) do
		if v and v.Character and v.Character:FindFirstChild('Humanoid') and v.Character.Humanoid.Health > 0 and v.Character:FindFirstChild('Alive') then
			v:LoadCharacter()
		end
	end

	if Winner then
		RemoteEvent:FireAllClients({ "Intermission", "Display", Winner.Name .. " wins with a depth of " .. highestDepth .. " studs!", 5 })
	else
		RemoteEvent:FireAllClients({ "Intermission", "Display", "No winner this time!", 5 })
	end
	wait(5)
	Fix = true
end

--// RemoteEvent Manager
RemoteEvent.OnServerEvent:Connect(function(Player, Input)
	if Input[1] == "M1" then
		local index = combat._records[Player]
		index:M1()
	end
end)

--// RemoteFunction Manager
RemoteFunction.OnServerInvoke = function(Player, Input)
	
end

--// Loop
while true do
	local PlayerCount = #game.Players:GetPlayers()
	if PlayerCount >= 1 then
		Timer = 30
		RemoteEvent:FireAllClients({ 'Intermission', 'Display', 'Intermission',30})
		repeat
			Timer = Timer -1
			GameValues.Settings.Timer.Value = Timer
			RemoteEvent:FireAllClients({ 'Timer', 'Display', Timer})
			wait(1)
		until Timer <= 0
		wait(1)
		RemoteEvent:FireAllClients({ 'Timer', 'Hide'})
		RemoteEvent:FireAllClients({ 'Intermission', 'Hide' })
		Timer = 50*4
		Fix = false
		SetupRound()
		LaunchRound()
		repeat wait() until Fix
	else
		--local coinD = GameValues.Currneyc.CoinSpawner
		--if coinD then
			--SpawnCoins(coinD)
		--end
		RemoteEvent:FireAllClients({ 'Intermission', 'Display', '2 Players Needed('..#game.Players:GetPlayers()..')!',5})
	end
	wait(5)
end

Could you provide the new issues/errors that are occurring? I don’t have the same file as you with the map/required objects. So I can’t just copy-paste the code into my studio to test.

This will be useful to you.

How to get the player, server-side, client side and remote events