|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 03:36 PM |
Accidentally* Stupid auto-correct. |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2014 03:37 PM |
| Oh that's true lol. Well I'll try with it. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
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 |
|
|
|
| 24 Jul 2014 03:57 PM |
| It still doesn't working... |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2014 04:00 PM |
"local func = functions[#functions];" You forgot to use math.random |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| Joined: 24 Jul 2012 |
| Total Posts: 651 |
|
| |
|