Module Script cant find Humanoid

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Make a module script for a sword
  2. What is the issue? Include screenshots / videos if possible!
    In the module script I reference the tool and try and find humanoid by finding the first child of tool.Parent.Parent! also when I load the animation it says attempt to index nil with LoadAnimation Sword_Module (DelphinusTheDev Editing) - Roblox Studio 7_30_2021 1_56_55 PM|690x356
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried debugging the script and adding prints like if humanoid then print(“Humanoid”) else print(“None”). None got printed out. I even tried changing tool.Parent.Parent to just tool.Parent
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

I’m not sure how to deal with humanoids in modulescripts but I have a solution in mind, I’ll describe it soon. Also, humanoid:LoadAnimation is deprecated, use humanoid.Animator:LoadAnimation

1 Like

Maybe you could use a load the animations when a player calls swing(), keep the player and the animationtrack created in a dictionary like this:

local loadedanims = {
player1.Character = animationtrack
}

initially it wont look like the one i’ve put but it gives an idea of what to put in the table

when swing() is called, check if the player isnt in the table then get their humanoid/animator and load the animation, and call :Play() when needed, though you may need to put the player as a parameter in the swing() function to check whether the player is in the table. This is how I would do it

But I would need to load the animation in the humanoid and for some reason when I do character:FindFirstChild(“Humanoid”) the Humanoid isn’t found?

try check what is character then

The character is found by the script I tested it using print. I wrote if character then print character.Name and it printed my name.

Your use of the MoudleScript completely defeats why they exist, but your .swing() function is tyring to use hit which isn’t listed in your function’s parameters.

Wdym it defeats the purpose? I am using the module script so I can replicate the data written in it to other sword scripts?

Yes hit is listed in the parameters if you checked. There is one built in function in swing.

Apologies, didn’t see the nested Touch Function, but for using a ModuleScript like this would defeat the purpose as this ModuleScript will be copied into each tool, so each tool would have it’s own ModuleScript… So nothing would be shared.

I get what your saying. Your saying that if I require the module in each sword I cant change the damage and stuff so its pointless?

It’s just an awkward spot to store a ModuleScript. Put it in a more fitting container, ServerStorage or ServerScriptService works.

If I put it in server storage and then required the module in every sword would I be able to make the damage and other variables different but not change the other swords variables. Also do you know the solution to my problem?

I am just going to use a script instead of a module.