generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Tracking math.random()

Previous Thread :: Next Thread 
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
14 Jul 2014 06:45 PM
So, I need my Tool to randomly play one of the 4 animations. But there is one which needs a special touch to it, and I don't know how to make if statement that tracks if the animation is the animation that needs the special touch.

This is what I got so far:

AnimTable = {Tool:WaitForChild("Attack1"), Tool:WaitForChild("Attack2"), Tool:WaitForChild("Attack3"), Tool:WaitForChild("Attack4")}
swoosh = Handle:WaitForChild("Swoosh") -- This is actually in Handle


function lmc()
if Tool.Enabled == false then
return
end
attack = plr:WaitForChild("Humanoid"):LoadAnimation(AnimTable[math.random(1,#AnimTable)])
attack:Play()
Tool.Enabled=false
wait(0.4)
swoosh:Play()
wait(0.45)
Tool.Enabled=true
end

Tool.Activated:connect(lmc)
Report Abuse
LetUsGame is not online. LetUsGame
Joined: 09 Nov 2013
Total Posts: 199
14 Jul 2014 06:46 PM
local chosen = math.random(1,#AnimTable)
if chosen== 2 then
--stuff
end
attack = plr:WaitForChild("Humanoid"):LoadAnimation(AnimTable[math.random(1,#AnimTable)])
Report Abuse
LetUsGame is not online. LetUsGame
Joined: 09 Nov 2013
Total Posts: 199
14 Jul 2014 06:46 PM
I'm just kidding:

local chosen = math.random(1,#AnimTable)
if chosen== 2 then
--stuff
end
attack = plr:WaitForChild("Humanoid"):LoadAnimation(AnimTable[chosen])
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
14 Jul 2014 06:55 PM
What does the 2 stand for?
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
14 Jul 2014 07:00 PM
AnimTable = {Tool:WaitForChild("Attack1"), Tool:WaitForChild("Attack2"), Tool:WaitForChild("Attack3"), Tool:WaitForChild("Attack4")}

You have 4 animations so '2' would be Attack2.
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
14 Jul 2014 07:01 PM
chosen = AnimTable[math.random(1,#AnimTable)]
attack = plr:WaitForChild("Humanoid"):LoadAnimation(chosen)
Report Abuse
LetUsGame is not online. LetUsGame
Joined: 09 Nov 2013
Total Posts: 199
14 Jul 2014 07:01 PM
It's arbitrary; it can be any number. If it's 2, the 2nd attack in the table is the one that's chosen.
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
14 Jul 2014 07:29 PM
Kk, thank you. :3
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
14 Jul 2014 07:34 PM
So how would this be worked out in my script? Maybe that way I can learn it better.


function lmc()
if Tool.Enabled == false then
return
end
attack = plr:WaitForChild("Humanoid"):LoadAnimation(AnimTable[math.random(1,#AnimTable)])
attack:Play()
Tool.Enabled=false
wait(0.4)
swoosh:Play()
wait(0.45)
Tool.Enabled=true
end
Report Abuse
robotmega is not online. robotmega
Joined: 16 May 2009
Total Posts: 14084
14 Jul 2014 08:00 PM
I'm 15, and an advanced scripter and builder. I try to keep up with my messages, but i cannot promise a respond. If you really want me to see your message, talk to me on
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
14 Jul 2014 08:59 PM
Nice respond. Also, if you're trying to qoute the fact I stated I'm an advanced scripter, it is true. I haven't took an in-depth look in animations. Advanced scripters don't know everything, too.
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
14 Jul 2014 09:07 PM
In my opinion, advanced scripters aren't ment to know everything about scripting. Some focus on certain things and get specialized in that. Some get a bit of everything. Just saying my opinion.
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
14 Jul 2014 09:13 PM
This isn't advanced and you've already been told what to do.
What you're doing:
Table[math.random(#Table)]

What you need to do:
RandomIndex = math.random(#Table)
if RandomIndex = GENERICNUMBER then
--script when it's a certain index
end
Table[RandomIndex] -- Do whatever you're doing with your table
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
16 Jul 2014 01:06 AM
@Above

It isn't advanced, indeed. It is simply... Hard to understand, because I didn't use math.random a lot, so now I don't have a lot of comprehension about how it works. (well, what you can do with it).
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
16 Jul 2014 01:09 AM
Here is how I understand it:


function lmc()
if Tool.Enabled == false then
return
end
attack = plr:WaitForChild("Humanoid"):LoadAnimation(AnimTable[math.random(1,#AnimTable)])
attack:Play()
if attack == 3 then
print("Special animation")
else
print("Regular animation")
end
end
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
16 Jul 2014 11:06 AM
function lmc()
if Tool.Enabled == false then
return
end
num = math.random(1,#AnimTable)
attack = plr:WaitForChild("Humanoid"):LoadAnimation(AnimTable[num])
attack:Play()
if num == 3 then
print("Special animation")
else
print("Regular animation")
end
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image