Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesnt it pick random?

Asked by 8 years ago

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

0
Could you provide the exact output, please? Goulstem 8144 — 8y
0
13:23:45.361 - ServerScriptService.CubeSpawn2:4: attempt to get length of global 'CubeDisplay' (a nil value) UltraUnitMode 419 — 8y

2 answers

Log in to vote
0
Answered by
Vitou 65 Snack Break
8 years ago

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".

0
Didnt work, But thanks for that.It still says the same thing.. UltraUnitMode 419 — 8y
Ad
Log in to vote
0
Answered by
ItsMeKlc 235 Moderation Voter
8 years ago

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

Answer this question