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

How do i Set math.random to set Current_Taunt...?

Asked by 9 years ago

How do i Set math.random to set Current_Taunt to a Random Value inside the TauntsID Table?

TauntsID = {138093241,130779878, 15331714, 139455448, 132179181, 140649307}
for _, asset in ipairs(TauntsID) do
     Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset)
end
Sounds.TauntS.Parent = Client_Char.Head
TauntS = Client_Char.Head.TauntS



Client_Mouse.KeyDown:connect(function(TKey_Val)
if (TKey_Val == "g") and not (TauntDeb) then
Current_Taunt = math.random(1,#TauntsID)
TauntS.SoundId = "http://www.roblox.com/asset/?id="..Current_Taunt
wait(1)
TauntDeb = true
TauntS:play()
wait(15)
TauntDeb = false
end 
end)
1
Wow, I didn't think of that XDDDDDDddd Blockeus 68 — 9y

3 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

In a table, you can take the table's name followed by brackets and a number, and that gives you the value corresponding to the number, like this:

MyTable = {"Hi","People","I'm","Perci1!"}
print(MyTable[1])
print(MyTable[3])
--output: Hi, I'm

Therefore we can get a random value by getting a random number.

MyTable = {"Hi","People","I'm","Perci1!"}
randomNumber = math.random[1,#MyTable] --#MyTable is the amount of values in the table. In this situation, 4.
randomValue = MyTable[randomNumber]
print[randomValue]

This is one way of doing it, but it would be easier to do it all in 1 step.

MyTable = {"Hi","People","I'm","Perci1!"}
print(MyTable[math.random(1,#MyTable)])

The same method applies to your script.

Ad
Log in to vote
-1
Answered by
Nymint 85
9 years ago
local Current_Taunt=TauntsID[math.random(1,#TauntsID)]
0
Please don't just post code, explain what you're doing. Perci1 4988 — 9y
0
You do realize he already knows the logic of it, he just wanted to know correct code, right? Nymint 85 — 9y
0
You can't just negative rep all of us like that, we still helped, that's just mean, dude. Nymint 85 — 9y
Log in to vote
-1
Answered by
Sublimus 992 Moderation Voter
9 years ago

Set it to a random index value of the table:

Current_Taunt = TauntsID[math.random(#TauntsUD)]

Answer this question