So, I'm trying to make this script play multiple animations. The output says nothing is wrong, but it won't work. For reference, the game is in FE.
local debounce = false local leftp = false local Character = game.Players.LocalPlayer.Character function onKeyPress(inputObject, gameProcessedEvent) if not debounce then if inputObject.KeyCode == Enum.KeyCode.Q then debounce = true leftp = not(leftp) end end end if leftp then local animation = script.LPunch local anim = Character.Humanoid:LoadAnimation(animation) anim:Play() debounce = true wait(0.3) debounce = false else local animation2 = script.RPunch local anim2 = Character.Humanoid:LoadAnimation(animation2) anim2:Play() debounce = true wait(0.3) debounce = false end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Hey TheCrimsonVortex,
local uis = game:GetService("UserInputService"); local plrs = game:GetService("Players"); local cool_down, anim = true, false -- cool_down is the debounce of this function, and anim is the switch of this function. When anim is false, one statement runs and when anim is true another statement runs. local t = 1 -- The amount of time that it's allowed to cool down. uis.InputBegan:Connect(function(obj, gp) -- Anonymous function with obj and gp as parameters. if obj.KeyCode == Enum.KeyCode.Q and not gp then -- Checks if the character pressed 'Q' and if he/she did it while typing or not. if cool_down then cool_down = false; if anim then -- Checks if anim is true, and if so runs this statement -- BLah blah. print("Play anim 1."); else -- If anim is false, it will run the statement below. -- Blah blah. print("Play anim 2."); end anim = not anim; -- Makes anim opposite to its previous value. wait(t); -- Wait for cool down. cool_down = true; -- Sets cool_down back to true in order to let the function run again. end end end)