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?
Grayseon
(Grayseon)
May 12, 2021, 12:15pm
2
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.
octav20071:
local char = player.Char
Isn’t this meant to be local char = player.Character
1 Like
Oopsies, fixed that. Still, the animation doesn’t plays
Grayseon
(Grayseon)
May 12, 2021, 12:20pm
6
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)
Scefrom
(scefrom)
May 12, 2021, 12:22pm
7
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?
octav20071:
local script
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
Scefrom
(scefrom)
May 12, 2021, 12:27pm
10
Does the output give you an error?
1 Like