My code is as follows:
wait(3)
local player = script.Parent.Parent.Name;
local Humanoid = game.Workspace[player];
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
local test = Humanoid.Humanoid:LoadAnimation(game.Workspace.Animation);
test:Play()
wait(1)
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Everything works fine, except that if you spam E you would be able to keep re-playing the animation without finishing its cycle. I want to add a wait() somewhere so the animation does not repeat until a certain time. What is the exact point to add it? Thanks.
Edit 1: My goodness, everything I post a question on here I manage to answer it almost immediately. If anyone has the same question, my code is as follows:
wait(3)
local player = script.Parent.Parent.Name;
local Humanoid = game.Workspace[player];
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
if script.Name == "Script" then
local test = Humanoid.Humanoid:LoadAnimation(game.Workspace.Animation);
test:Play()
script.Name = "waiter"
wait(1.4)
script.Name = "Script"
end
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
