Roblox states " invalid argument #2: random interval empty

I want to make an orb spawn in a random position in an area.

It keeps saying that the argument

I tried making the game wait because this is a cloned model rather than a previously existing one. I also tried making the “WaitForChild(”“)” just a blunt period.
– I can assure you that OrbAreaZ1 & 2 are both areas, same with the Xs

local Player = game.Players.LocalPlayer.Character
local function ADDWALL()
	if Player.FightEnabler.Value == true then
		local Wall =  game.ReplicatedStorage.Wall:Clone()
		Wall.Parent = game.Players.LocalPlayer.Character
		Wall:PivotTo(CFrame.new(Player.HumanoidRootPart.Position.X, (Player.HumanoidRootPart.Position.Y-5), Player.HumanoidRootPart.Position.Z))
		Wall:ScaleTo(Player.Range.Value)
	end
end
game.Players.LocalPlayer.Character:WaitForChild("FightEnabler"):GetPropertyChangedSignal("Value"):Connect(ADDWALL)
ADDWALL()
local function StartOrbs()
	if Player.FightEnabler.Value == true then
		local Arrow = game.ReplicatedStorage.Orbs.StackBow.ArrowOrb:Clone()
		Arrow.Parent = workspace
		local OrbPositionZ = math.random(Player:WaitForChild("Wall"):WaitForChild("OrbAreaZ1").Position.Z, Player:WaitForChild("Wall").OrbAreaZ2.Position.Z)
		local OrbPositionX = math.random(Player.Wall.OrbAreaX1.Position.X, Player.Wall.OrbAreaX2.Position.X)
		local OrbPositionY = Player.Wall:GetModelCFrame()
		Arrow:PivotTo(CFrame.new(OrbPositionX, (OrbPositionY.Y + 10), OrbPositionZ))
		print(OrbPositionX)
		print(OrbPositionZ)
		print("WORK")
	end
	print("FAIL-URE")
end
Player:WaitForChild("FightEnabler"):GetPropertyChangedSignal("Value"):Connect(StartOrbs)
StartOrbs()

Try removing the waitforchild’s

It just states that the position is nil, are you sure the model is exisiting?

I’m pretty sure the error means that the upper bound (second argument) is less than the lower bound (first argument).

local z1 = Player:WaitForChild("Wall"):WaitForChild("OrbAreaZ1").Position.Z
local z2 = Player:WaitForChild("Wall").OrbAreaZ2.Position.Z
local minZ, maxZ = math.min(z1, z2), math.max(z1, z2)
local OrbPositionZ = math.random(minZ, maxZ)

local x1 = Player.Wall.OrbAreaX1.Position.X
local x2 = Player.Wall.OrbAreaX2.Position.X
local minX, maxX = math.min(x1, x2), math.max(x1, x2)
local OrbPositionX = math.random(minX, maxX)

I already said I tried that before

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