Help with module script

I am a VERY beginner to ModuleScripts, and I would want some help.
I made a test module using the following code:

local module = {}

function module.PlayAnim(player, anim)
	local char = player.Char
	char.Humanoid.Animator:LoadAnimation(anim):Play()
end

return module

And then I used in a local script the following code:

local module = require(game.ReplicatedStorage.PlayAnimModule)
local anim = script.AttackAnim
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	module.PlayAnim(plr, anim)
end)

Although the animation doesn’t plays. Any help?

Change char.Humanoid.Animator:LoadAnimation(anim):Play() in the module to char.Humanoid:LoadAnimation(anim):Play()

I know that is deprecated, but I will try it.

Isn’t this meant to be local char = player.Character

1 Like

Oopsies, fixed that. Still, the animation doesn’t plays :confused:

Change the localscript to

local module = require(game.ReplicatedStorage.PlayAnimModule)
local anim = script.AttackAnim.AnimationId
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	module.PlayAnim(plr, anim)
end)

This reply might be useless

I suggest you to try doing some debug if you didn’t already, for example, does the Proximity event fire? Does the module function fire?
you can add some prints to check it, for example:

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
    print("fired")
	module.PlayAnim(plr, anim)
end)

if it prints “fired”, the event worked well, so the problem may stay on arguments or on the module function.

1 Like

I put a print right after the trigger, but it doesn’t prints. That may be the problem. How to solve it tho?

Local scripts don’t run in workspace which I see since you script Parent in the next line in the proximity prompt.

Use a normal server script to make it run.

2 Likes

Does the output give you an error?

1 Like