ModuleScript: Getting the character who required it

I’m trying to get the character of whoever called the modulescript, but I’m confused on how to do it because it automatically runs, I’m not sure how to explain myself…
I’ll show an example.
imagen
This is the start of my lib module, and
imagen
this is the script that is causing trouble, because it’s not in a player and instead in a humanoid rig, so it attempts to get the plr.Character, fails, then stops the module altogether. I just need to find a way to get the character of whoever called it.

1 Like

I don’t think you can call the Player or Character as a variable in a ModuleScript. You would have to create a function inside the ModuleScript.

Something like this

function Lib:GetCharacter(Player: Player)
	local Character = Player and Player.Character
    print(Character)
end

And then call it like this

Lib:GetCharacter(Player)
1 Like

Doing Player.Character on the module script works perfectly fine for the player, just that I’m not sure how to do it for NPCs, they have a script inside which is just this, it’s creating problems because it looks for the local player, and the character for them. I just need to get the model of whoever required the modulescript
imagen

Nevermind. I just decided to fix it by just adding the function on the attacking script itself. Thanks for trying to help, though.

No problem, good luck with your game :smiley: !

1 Like