Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesnt it pick random?

I'm trying to make a randomize cube picker and it spawns randomly were the CubePlaces CFrame are, But it didnt work.

The output said something about an nil value.

local CubeDisplays = game.ReplicatedStorage.CubeDisplay:GetChildren()
local CubePlaces = game.Workspace.CubePlaces:GetChildren()
local CubePlacesPart = game.Workspace.CubePlaces
CubeDisplay = math.random(1, #CubeDisplay)
CubeChosen = CubeDisplay[CubeDisplay]
CubeChosen:Clone().Parent = game.Workspace
CubeChosenClone = CubeChosen:Clone()
CubeChosenClone.Parent = game.Workspace
CubePlace = math.random(1, #CubePlaces)
CubeChosenClone.CFrame = CubePlace.CFrame

2 comments

0

Could you provide the exact output, please?

0

13:23:45.361 - ServerScriptService.CubeSpawn2:4: attempt to get length of global 'CubeDisplay' (a nil value)

2 answers

Here's a fix, it should work :

local CubeDisplays = game.ReplicatedStorage.CubeDisplays:GetChildren()
local CubePlaces = game.Workspace.CubePlaces:GetChildren()
local CubePlacesPart = game.Workspace.CubePlaces

CubeDisplays = math.random(1, #CubeDisplays)
CubeChosen = CubeDisplays[CubeDisplays]
CubeChosen:Clone().Parent = game.Workspace
CubeChosenClone = CubeChosen:Clone()
CubeChosenClone.Parent = game.Workspace
CubePlace = math.random(1, #CubePlaces)
CubeChosenClone.CFrame = CubePlace.CFrame

You forgot the "s" after "CubeDisplay".

1 comment

0

Didnt work, But thanks for that.It still says the same thing..

I'm not sure why, but to fix it just put math.randomseed(tick()) before you use math.random

This discussion is preserved as it was. New answers, comments, and votes are closed.