Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you help me correct my LocalScript animation script ?

Asked by 1 year ago
Edited 1 year ago
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

1 answer

Log in to vote
0
Answered by 1 year ago

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.

0
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. T3_MasterGamer 2189 — 1y
Ad

Answer this question