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

My math.Random isnt working?

Asked by
neoG457 315 Moderation Voter
9 years ago
storage = game.ReplicatedStorage:GetChildren()
backpack = game.Players.LocalPlayer.Backpack
math.randomseed(tick())

storage["Kagune" .. tostring(math.random(8))]:clone().Parent = backpack

I have 8 Different local scripts in Replicated storage this script should put a random 1 in my backpack when I enter the game but it doesnt.

This is in a local script in StarterPack and the 8 local scripts I have are:

Kagune1 Kagune2 Kagune3 Kagune4 Kagune5 Kagune6 Kagune7 Kagune8

There are other things in Replicated Storage such as models.

0
It is easier to use the "PlayerGui" then "Backpack" woodengop 1134 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

"storage" is a list of children, but you're indexing it with a string key (the name of the script). Get rid of the ":GetChildren()" part on the first line and it should work.

Ad
Log in to vote
-1
Answered by 9 years ago

you have to put 2 arguments into math.random().

So if you want 1-8, you would do

math.random(1,8)

so for your code it would become:

storage = game.ReplicatedStorage:GetChildren()
backpack = game.Players.LocalPlayer.Backpack
math.randomseed(tick())

local kaguneClone = storage["Kagune" .. tostring(math.random(1,8))]:Clone()
kaguneClone.Parent = backpack

I changed the cloning line so it would be easier to read^^

0
Wrong. If only one argument is given, math.random automaitcally makes the range from 1 - given arg. DigitalVeer 1473 — 9y

Answer this question