Ad
Log in to vote
1

'Attempt to index number with 'Clone'' error occuring in my math.random script?

Asked by 12 days ago

So i have a parkour script that loads a different parkour map from a folder in server storage that moves it to workspace and moves the position. But im getting the error 'Attempt to index number with 'Clone' '. So the script is

local roundLenth = 35
local intermissionLenth = 6
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.Lobby.LobbySpawn
local GameAreaSpawn = game.Workspace.GameTPPart

InRound.Changed:Connect(function()
    if InRound.Value == true then
        local Item = game.ServerStorage.Obbys:GetChildren()
        local randomItem = math.random(#Item)
        local clonedobby randomItem:Clone()
        clonedobby.Parent = workspace
        clonedobby.ObbyStart.CFrame = GameAreaSpawn.CFrame
        for _, player in pairs(game.Players:GetPlayers()) do
            local char = player.Character
            char.Humanoid.WalkSpeed = 30
            char.HumanoidRootPart.CFrame = GameAreaSpawn.CFrame
        end
    else
        if InRound.Value == false then
            for _, player in pairs(game.Players:GetPlayers()) do
                local char = player.Character
                char.Humanoid.WalkSpeed = 16
                char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
            end
        end
    end
end)

local function roundTimer()
    while wait() do
        for i = intermissionLenth, 1, -1 do
            wait(1)
            InRound.Value = false
            Status.Value = "Intermission: ".. i .." Seconds Left!"
        end
        for i = roundLenth, 1, -1 do
            wait(1)
            InRound.Value = true
            Status.Value = "Game Time: ".. i .." Seconds Left!"
        end
    end
end

spawn(roundTimer)

And the error part was

local Item = game.ServerStorage.Obbys:GetChildren()
        local randomItem = math.random(#Item)
        local clonedobby randomItem:Clone()
        clonedobby.Parent = workspace
        clonedobby.ObbyStart.CFrame = GameAreaSpawn.CFrame

so for some reason its attempting to index a number with clone? Is it a punctuation error or is it completely wrong?

1 answer

Log in to vote
1
Answered by 12 days ago
Edited 12 days ago
local randomItem = math.random(#Item)

means the number, consider using

local randomItem = Item[math.random(1, #Item)]
Ad

Answer this question