Invalid argument #2 to 'random' (interval is empty) in line 11

local Spawns = workspace.Spawns:GetChildren()

game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(Char)
		
		repeat wait() until Char and Spawns
		
		local ChosenSpawnArea = math.random(1,#Spawns)
		
		local ChosenPos = CFrame.new(math.random(Spawns[ChosenSpawnArea].X1.Position.X,Spawns[ChosenSpawnArea].X2.Position.X),0.5,math.random(Spawns[ChosenSpawnArea].Z1.Position.Z,Spawns[ChosenSpawnArea].Z2.Position.Z))
		
		Char.HumanoidRootPart.CFrame = ChosenPos
		
		Char.HumanoidRootPart.Orientation = Spawns[ChosenSpawnArea].Orientation
		
		Char.Humanoid.Died:Connect(function()
			
			if player.leaderstats:FindFirstChild("Time Played").Value >= 900 then
				
				wait(2)
				
				player:LoadCharacter()
				
			end
			
		end)
		
	end)
	
end)

math.random must have the values in ascending order so math.random(1, 5) works but math.random(5, 1) will not. If you print out the X/Z values that you are using in math.random you will see that they are not in the correct order most likely. If this is really what you want you should probably use math.min and math.max to set up variables that will be in the correct order.

how would i use math.min and math.max

Replace this:

With this:

local xMin = math.min(Spawns[ChosenSpawnArea].X1.Position.X, Spawns[ChosenSpawnArea].X2.Position.X)
local xMax = math.max(Spawns[ChosenSpawnArea].X1.Position.X, Spawns[ChosenSpawnArea].X2.Position.X)
local zMin = math.min(Spawns[ChosenSpawnArea].Z1.Position.Z,Spawns[ChosenSpawnArea].Z2.Position.Z)
local zMax = math.max(Spawns[ChosenSpawnArea].Z1.Position.Z,Spawns[ChosenSpawnArea].Z2.Position.Z)
local ChosenPos = CFrame.new(math.random(xMin, xMax),0.5,math.random(zMin, zMax))

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.