Hello , I'm trying to launch random functions that are in a table. This is what I'm currently trying: I changed some of the code
c=script.Parent L1=c.Lane1 L2=c.Lane2 L3=c.Lane3 L4=c.Lane4 Key = {} Key.Left = function (Left) L1.A1:TweenPosition(UDim2.new(0,0,-0.137,0)"Out","Quad",4)end Key.Down = function (Down) L2.A2:TweenPosition(UDim2.new(0,0,-0.137,0)"Out","Quad",4)end Key.Up = function (Up) L3.A3:TweenPosition(UDim2.new(0,0,-0.137,0)"Out","Quad",4)end Key.Right = function(Right) L4.A4:TweenPosition(UDim2.new(0,0,-0.137,0)"Out","Quad",4)end wait(1) while true do Key[math.random(#Key.Left,Key.Down,Key.Right,Key.Up)]() end
This is the output :
Players.Player1.PlayerGui.GuiGame.DDR.Script:16: attempt to get length of field 'Left' (a function value)
Here you go.
I tested it, it's working perfectly.
c=script.Parent L1=c.Lane1 L2=c.Lane2 L3=c.Lane3 L4=c.Lane4 function Key1() L1.A1:TweenPosition(UDim2.new(0,0,-0.137,0)"Out","Quad",4) end function Key2() L2.A2:TweenPosition(UDim2.new(0,0,-0.137,0)"Out","Quad",4) end function Key3() L3.A3:TweenPosition(UDim2.new(0,0,-0.137,0)"Out","Quad",4) end function Key4() L4.A4:TweenPosition(UDim2.new(0,0,-0.137,0)"Out","Quad",4) end Fire={Key1,Key2,Key3,Key4} while wait() do Pat = Fire[math.random(1, #Fire)] Pat() end