player = game.Players.LocalPlayer
local Block = player.Character.Humanoid:LoadAnimation(4819470970)
local Weaponblock = player.Character.Humanoid:LoadAnimation(4819498690)
local Weaponblockshield = player.Character.Humanoid:LoadAnimation(4819501037)
local Stance = player.Character.Humanoid:LoadAnimation(4812358432)
local m = {}
function m.PlayAnimation(anim)
local success,err = pcall(function()
if anim == "Block" and Block ~= nil then
Block:Play()
end
if anim == "Weaponblock" and Weaponblock ~= nil then
Weaponblock:Play()
end
if anim == "Weaponblockshield" and Weaponblockshield ~= nil then
Weaponblockshield:Play()
end
if anim == "Stance" and Stance ~= nil then
Stance:Play()
end
end)
end
function m.StopAnimation(anim)
local success,err = pcall(function()
if anim == "Block" and Block ~= nil then
Block:Stop()
end
if anim == "Weaponblock" and Weaponblock ~= nil then
Weaponblock:Stop()
end
if anim == "Weaponblockshield" and Weaponblockshield ~= nil then
Weaponblockshield:Stop()
end
if anim == "Stance" and Stance ~= nil then
Stance:Stop()
end
end)
end
function m.SetAnimation(anim, id)
local success,err = pcall(function()
if anim == "Block" then
Block = id
end
if anim == "Weaponblock" then
Weaponblock = id
end
if anim == "Weaponblockshield" then
Weaponblockshield = id
end
if anim == "Stance" then
Stance = id
end
end)
end
function m.StopAll()
local success,err = pcall(function()
Block:Stop()
Weaponblock:Stop()
Weaponblockshield:Stop()
Stance:Stop()
end)
end
return m
COMMUNITY QUESTION
Can you help me correct my LocalScript animation script ?
1 answer
You can't put variables outside the module script table. Those variables will not work. I don't know much about ModuleScripts (yet), so that's that. Just put all the variables inside the m table. Plus, local variables that are not in a specific script scope don't need to be changed. Local Variables load faster anyway, so its better.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
You're wrong, you can still put variables outside the module table in a ModuleScript. The variables will only work if the ModuleScript has been required.