local AnimationEvent1 = game.ReplicatedStorage.AnimationEvent1 local AnimationEvent2 =…
- User
local AnimationEvent1 = game.ReplicatedStorage.AnimationEvent1 local AnimationEvent2 = game.ReplicatedStorage.AnimationEvent2
local animations = { {cooldown = 25/60, event = AnimationEvent1}, {cooldown = 30/60, event = AnimationEvent2}, } local UIS = game:GetService("UserInputService") local lastAnimationTimes = {}
UIS.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.E then local currentTime = os.clock() if not lastAnimationTimes[1] or currentTime - lastAnimationTimes[1] >= animations[1].cooldown then animations[1].event:FireServer() lastAnimationTimes[1] = currentTime end endHow can I update this roblox studio LUA script so that the player must ONLY be pressing E in order to play an animation
- Assistant
local AnimationEvent1 = game.ReplicatedStorage.AnimationEvent1 local AnimationEvent2 = game.ReplicatedStorage.AnimationEvent2
local animations = { {cooldown = 25/60, event = AnimationEvent1}, {cooldown = 30/60, event = AnimationEvent2}, } local UIS = game:GetService("UserInputService") local lastAnimationTimes = {}
UIS.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.E then local currentTime = os.clock() local canPlayAnimation = true
for i = 1, #lastAnimationTimes do if lastAnimationTimes[i] and currentTime - lastAnimationTimes[i] < animations[i].cooldown then canPlayAnimation = false break end end if canPlayAnimation then animations[1].event:FireServer() lastAnimationTimes[1] = currentTime end end endend)
-- Note: This updated script assumes that there could be multiple animations with different cooldowns. The script checks if all animations are ready to be played before playing the animation from the first element of the animations array. If any of the animations is still on cooldown, it will prevent the animation from being played.