I'm writing a sword script. When someone clicks, A random selection (of 3) is ticked. This plays an animation via the Animation Script. I get this error:
19:21:14.931 - Argument 1 missing or nil 19:21:14.931 - Script 'Players.Player.Backpack.Wooden Sword.SwordScript', Line 155 19:21:14.932 - Stack End
and I have no idea why. I have never come across this error before. This is the part of the script that errors.
function onActivated() if not Tool.Enabled then return end Tool.Enabled = false local character = Tool.Parent; local humanoid = character.Humanoid if humanoid == nil then return end attack() local num = 5 --Change 5 to the number of maps you have local anims = {"PlayThrust", "PlaySlash", "PlayOverhead"} --Put their names here, add more if you have to local m = math.random(1,num) script.Parent:findFirstChild(anims[m]).Value = true --error here wait(1) Tool.Enabled = true end
Any help is appreciated. Thanks!
You have a table called anims
that holds 3 values and a variable called num
with the value 5
You are calling a random number between 1 and num
or 5
when there are only 3 values in the anims table.
local num = 5 --Value is 5 local anims = {"PlayThrust", "PlaySlash", "PlayOverhead"} --Only 3 indexes local m = math.random(1,num) --Random number between 1-5 script.Parent:findFirstChild(anims[m]).Value = true --If the random number is greater than 3, it will be nil
If the math.random
returns something greater than 3 it will be nil and give an error.
Let me know if that is your issue, if not I will look into it further!