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

Math.Random and string won't work together?

I am getting nil value on line 13

What am I missing? It works if its only 1 item. but I need to do multiple.

local ReplicatedStorage = game.ServerStorage
local A = ReplicatedStorage:WaitForChild('Asher')
local B = ReplicatedStorage:WaitForChild('Banana')
local T = ReplicatedStorage:WaitForChild('Trump')
local U = ReplicatedStorage:WaitForChild('Unicorn')
local DropperPart = workspace:WaitForChild('DropperPart') 


local Strings = {'A', 'B', 'T', 'U'}
local Boss = Strings math.random(1, #Strings)

while wait(math.random(8,18)) do
    local m = Boss:Clone()  -- this line
m.Parent = DropperPart
    
game:GetService('Debris'):AddItem(Boss,300)
end

1 answer

✓ Accepted answer

Well if you print this out

local Strings = {'A', 'B', 'T', 'U'}
local Boss = Strings math.random(1, #Strings)

you will get a table so what you want to do is

local Strings = {'A', 'B', 'T', 'U'}
local Boss = Strings[math.random(1, #Strings)]

Even if that is how you do it your script is all wrong it should say

local ReplicatedStorage = game.ServerStorage
local A = ReplicatedStorage:WaitForChild('Asher')
local B = ReplicatedStorage:WaitForChild('Banana')
local T = ReplicatedStorage:WaitForChild('Trump')
local U = ReplicatedStorage:WaitForChild('Unicorn')
local DropperPart = workspace:WaitForChild('DropperPart') 


local Strings = {A, B, T, U}
local Boss = Strings[math.random(1, #Strings)]

while wait(math.random(8,18)) do
    local m = Boss:Clone()  -- this line
m.Parent = DropperPart

game:GetService('Debris'):AddItem(Boss,300)
end

3 comments

0

workspace is deprecated

0

What do you mean by deprecated?

0

Nvm

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