I have made a few methods they work fine. How could I make it to where I want to call a random method without having to put all the code into one method. For example if I put the methods into an array they will all be called on the character and that not what I want. I could however put the code into a method called random but that seems like a lot of work.
**Method: **
function character:size(amount) local humanoid = self.location:findFirstChild("Humanoid") if humanoid:findFirstChild("BodyHeightScale") then humanoid.BodyHeightScale.Value = amount end if humanoid:findFirstChild("BodyWidthScale") then humanoid.BodyWidthScale.Value = amount end if humanoid:findFirstChild("BodyDepthScale") then humanoid.BodyDepthScale.Value = amount end if humanoid:findFirstChild("HeadScale") then humanoid.HeadScale.Value = amount end end
"For example if I put the methods into an array they will all be called on the character"
That's up to you, ex you could do local methodToRun = methods[math.random(1, #methods)]
(Edit)
Based on what you're trying to do, using anonymous methods may be better:
local methods = { function(self) self:color(0) end, function(self) self:size(10) end, --etc } -- to use a random one: methods[math.random(1, #methods)](testCharacter) -- replacing testCharacter with whatever character you want to act on. Whatever you send will be sent as 'self' in the anonymous methods, which then call the function. ex, if the first method is randomly chosen, this effectively runs "testCharacter:color(0)"
So i read the comment you posted. You said you had the methods like so:
local methods = { testCharacter:color(0), testCharacter:size(10)}
But you are invoking the method right then and there. What you would want to do is reference the function .
like so:
local methods = { testCharacter.color), testCharacter.size}
Then when you want to call it, just loop through the list or randomly choose one by using chess123mate answer and just add ()
to the end of methodToRun
to run the method.