I got an error that said:
Workspace.Trigger.Script:19: invalid argument #1 to ‘random’ (interval is empty) - Server - Script:19
I don’t know what to do at all. I checked other posts but they seem to have a different solution. What should I do in this case?
Code:
local Players = game:GetService('Players')
local ServerStorage = game:GetService('ServerStorage')
local Trigger = script.Parent
local Obby = Trigger.Parent
Trigger.Touched:Connect(function(part)
-- Check if the player touches it
local character = part.Parent
local player = Players:GetPlayerFromCharacter(character)
if not player then return end
-- Disable trigger
script.Enabled = false
-- Create a new obby
local ObbyStructure = ServerStorage:WaitForChild('ObbyStructure')
local Obbies = ObbyStructure:GetChildren()
local ChosenObby = Obbies[math.random(#Obbies)] -- Heres the problem
local ObbyCount = ServerStorage.Values:FindFirstChild('ObbyCount')
ObbyCount.Value += 1
local PreviousObby = workspace:FindFirstChild('Obby'..(ObbyCount.Value - 1)) or nil
local Finish = nil
if PreviousObby then Finish = PreviousObby:FindFirstChild('Finish') end
ChosenObby.Parent = workspace
ChosenObby.Name = 'Obby'..ObbyCount.Value
ChosenObby:PivotTo((Finish or workspace.StartSpawn.Finish).CFrame)
-- Obby to be destroyed
local ExistingObbies = ServerStorage.Values:FindFirstChild('ExistingObbies')
local ObbyTBD = workspace:FindFirstChild('Obby'..(ObbyCount.Value - ExistingObbies.Value))
if ObbyTBD then ObbyTBD:Destroy() end
-- Move and enable trigger
Trigger.Position = ChosenObby.Checkpoints.Checkpoint.Position + Vector3.new(0, 4.5, 0)
script.Enabled = true
end)