I am trying to make a sword for my game that will allow my character to block left when the q button is pressed but still play a animation to swing the sword. I haven't been scripting for long so it would be nice if you could point out all errors I have. This is the code I currently am working with. If you need any other scripts that I am working with to understand the problem I will gladly show you them. Thank you, -Peanut
local function WaitForChild(parent, childName) while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end return parent[childName] end local Tool = script.Parent local Animations = {} local MyHumanoid local MyCharacter local function PlayAnimation(animationName) if Animations[animationName] then Animations[animationName]:Play() end end local function StopAnimation(animationName) if Animations[animationName] then Animations[animationName]:Stop() end end function OnEquipped(mouse) MyCharacter = Tool.Parent MyHumanoid = WaitForChild(MyCharacter, 'Humanoid') if MyHumanoid then Animations['EquipAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'EquipAnim5')) Animations['IdleAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'IdleAnim3')) Animations['OverheadAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'OverheadAnim2')) Animations['SlashAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'SlashAnim2')) Animations['ThrustAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'ThrustAnim2')) Animations['UnequipAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'UnequipAnim2')) Animations['Blockleft'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'Blockleft')) end PlayAnimation('EquipAnim') PlayAnimation('IdleAnim') end function Blockleft(key) PlayAnimation('Blockleft') end function OnUnequipped() for animName, _ in pairs(Animations) do StopAnimation(animName) end end mouse.Keydown:connect(function(key)) if key == "q" then Tool.Equipped:connect('BlockLeft') end Tool.Equipped:connect(OnEquipped) Tool.Unequipped:connect(OnUnequipped) WaitForChild(Tool, 'PlaySlash').Changed:connect( function (value) PlayAnimation('SlashAnim') end) WaitForChild(Tool, 'PlayThrust').Changed:connect( function (value) PlayAnimation('ThrustAnim') end) WaitForChild(Tool, 'PlayOverhead').Changed:connect( function (value) PlayAnimation('OverheadAnim') end)
on line 56, you do this:
Tool.Equipped:connect('BlockLeft')
You're trying to connect a non-function value to the Equipped event. I don't know what you want to be executed there, but it needs to be a function, like so:
Tool.Equipped:connect(function(mouse) --your block code here end)