|
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) |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
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 |
|
|
What do you mean by local?
And it says it doesn't work.
this line -- env[func](); |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
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 |
|
|
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 |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
What is the output? |
|
|
This one:
env[func]();
16:18:49.068 - Script 'Players.Player1.PlayerGui.F to Flip', Line 153 |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
I need the actual output, not the trace.
Does it say " attempt to call global '___' (a nil value)"
or? |
|
|
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) |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Oh, I antecedently removed the 'player = game.Players.LocalPlayer ' |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Accidentally*
Stupid auto-correct. |
|
|
Oh that's true lol. Well I'll try with it. |
|
|
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... |
|
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
That's math.random's fault.
Add this to the top line: math.randomseed(tick());math.random();math.random(); |
|
|
It still doesn't working... |
|
|
"local func = functions[#functions];"
You forgot to use math.random |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
wow I dumb, yeah:
lacol func = functions[math.random(#functions)] |
|
|
Yeah, I knew that there was something missing... XD
It finally worked1 Thank you guys!
I hope you have a good day! |
|
BenocularJoin Date: 2012-07-24 Post Count: 652 |
:) |
|