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: math.random for running a random function

Previous Thread :: Next Thread 
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 03:12 PM
I want something that can run 3 different animations called from a function ( here's the 3 functions: FFf(),FFr() and FFl() ). I want that one of them is randomly chosen by a math.random. How can I do this?
Thank you in advance! (:


local mouse = game.Players.LocalPlayer:GetMouse()

function run(key)
if key == "f" then
player = game.Players.LocalPlayer
FFf() -- one of my 3 functions
end
end

mouse.KeyDown:connect(run)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 03:14 PM
local functions = {"FFf", "FFr", "FFI"};
local env = getfenv();

function run(key)
if key == "f" then
local func = functions[#functions];
env[func]();
end
end

mouse.KeyDown:connect(run)

Make sure your functions are not local
Report Abuse
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 03:20 PM
What do you mean by local?
And it says it doesn't work.
this line -- env[func]();
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 03:21 PM
Make sure the function exists (and that I spelled them right in the table)
I think I made a mistake and put I instead of l on the 3rd value of the table
Report Abuse
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 03:27 PM
I already corrected your "I" mistake but it steal not working.
And the three functions exist.
I can give you an example of them if it can helps you.

They are both same except for the line where I comment.

function FFl()
if debounce==true then return end
debounce=true
Char = player.Character
Human = Char.Humanoid
Torso = Char.Torso
CF = Torso.CFrame
Human.PlatformStand = false
Human.Sit = true
VelUp = Instance.new("BodyVelocity")
VelUp.velocity = Vector3.new(0,-5000,0)+Torso.CFrame.lookVector*15
VelUp.P = VelUp.P*-1000
VelUp.maxForce = Vector3.new(10000,10000,10000)*999
VelUp.Parent = Torso
coroutine.resume(coroutine.create(Down),VelUp)
Gyro = Instance.new("BodyGyro")
Gyro.P = Gyro.P*10
Gyro.maxTorque = Vector3.new(100000,100000,100000)*999
Gyro.cframe = CF
Gyro.Parent = Torso
for i=1, 14 do
Gyro.cframe = Gyro.cframe*CFrame.fromEulerAnglesXYZ(math.pi/-9,math.pi/-18,0) --here
wait()
end
Gyro.cframe = CF
wait()
Gyro:remove()
Human.PlatformStand = false
Human.Sit = false
_restoreproperties()
debounce=false
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 03:28 PM
What is the output?
Report Abuse
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 03:30 PM
This one:

env[func]();

16:18:49.068 - Script 'Players.Player1.PlayerGui.F to Flip', Line 153
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 03:31 PM
I need the actual output, not the trace.
Does it say " attempt to call global '___' (a nil value)"
or?
Report Abuse
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 03:35 PM
Oh. my bad. Yes it said:

16:18:49.065 - Players.Player1.PlayerGui.F to Flip:115: attempt to index global 'player' (a nil value)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 03:36 PM
Oh, I antecedently removed the 'player = game.Players.LocalPlayer '
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 03:36 PM
Accidentally*
Stupid auto-correct.
Report Abuse
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 03:37 PM
Oh that's true lol. Well I'll try with it.
Report Abuse
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 03:43 PM
It worked but it's doing the same move everytimes...
Except if I'm very unlucky, it's doing the same function.

It's doing FFl everytimes...
Report Abuse
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 03:52 PM
bump
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 03:52 PM
That's math.random's fault.
Add this to the top line: math.randomseed(tick());math.random();math.random();
Report Abuse
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 03:57 PM
It still doesn't working...
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
24 Jul 2014 04:00 PM
"local func = functions[#functions];"
You forgot to use math.random
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 04:02 PM
wow I dumb, yeah:
lacol func = functions[math.random(#functions)]
Report Abuse
PleasantKillerman is not online. PleasantKillerman
Joined: 01 Nov 2011
Total Posts: 668
24 Jul 2014 04:06 PM
Yeah, I knew that there was something missing... XD
It finally worked1 Thank you guys!
I hope you have a good day!
Report Abuse
Leg0brick is not online. Leg0brick
Joined: 24 Jul 2012
Total Posts: 651
24 Jul 2014 04:35 PM
:)
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