✓ Accepted answer
You're on the right track. Only a few changes. On line 13:
local moves = {skill1(), skill2(), skill3()}
What you're doing here is running each function and storing its return value in the table. Anytime you include the parenthesis, the VM thinks that you intend to run the function immediately. If you want to store the function, write it without the parenthesis.
local moves = {skill1, skill2, skill3}
By that same token, in order to run the function, you need to include the parenthesis. Looking at line 16; here, you're indexing the function but not calling it. In order to do so change it from:
moves[math.random[1,#moves]]
to
moves[math.random(1,#moves)]()
Also notice that the random() function uses a parenthesis rather than brackets. That has been changed to reflect. So for the final script:
function skill1()
print("Skill1")
end
function skill2()
print("Skill2")
end
function skill3()
print("Skill3")
end
local moves = {skill1, skill2, skill3}
while true do
moves[math.random(1,#moves)]()
wait(1)
end
4 comments
btw dont use spawn() if you dont want the attacks to stack
That does not do anything. Also, please explain your answer and do not simply post code. That's not the point of the site.
ok so every ~.03 seconds the function will be spawned with a random argument from 1 to 10, that argument will be used in the main function to see what attack it should make.
That is totally not what the point of the question is. The point of the question is calling a random FUNCTION, not a random ARGUMENT. It's called reading the question and not being blind.