✓ Accepted answer
I suppose you know how to use debounces?
To start I'll add a debounce for you.
local player = game.Players.LocalPlayer
local Tool = script.Parent
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local debounce = false
local waitTime = 5
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local AnimE = Instance.new("Animation")
AnimE.Name = "AnimE"
AnimE.Parent = script.Parent
AnimE.AnimationId = "http://www.roblox.com/asset/?id=6757120886"
local animEtrack = humanoid:LoadAnimation(AnimE)
UserInputService.InputBegan:Connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.E and not gameProcessed and not debounce then
debounce = true
animEtrack:Play()
wait(waitTime)
debounce = false
end
end)
Here is a page about debounces on Roblox's Developer page.
So this code makes you able to only play the animation every 5 seconds. And we use UserInputService to get the keypress as well as the gameProcessed Parameter instead of mouse.
Now if you want a Gui to shrink or something like that to indicate the time, then you could tween it.
So now I will just assume you have a Gui Frame that you want to tween.
local player = game.Players.LocalPlayer
local Tool = script.Parent
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local debounce = false
local waitTime = 5
local frame = player.PlayerGui:WaitForChild("ScreenGui").FrameToTween
local function debounceToFalse(didComplete)
if didComplete then
debounce = false
else
print("Something went wrong")
end
end
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local AnimE = Instance.new("Animation")
AnimE.Name = "AnimE"
AnimE.Parent = script.Parent
AnimE.AnimationId = "http://www.roblox.com/asset/?id=6757120886"
local animEtrack = humanoid:LoadAnimation(AnimE)
UserInputService.InputBegan:Connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.E and not gameProcessed and not debounce then
debounce = true
animEtrack:Play()
frame.Size = UDim2.new(0, 0, 0, 50)
frame:TweenSize(
UDim2.new(0, 100, 0, 50),
Enum.EasingDirection.In,
Enum.EasingStyle.Linear,
waitTime,
true,
debounceToFalse
)
end
end)
And here is a link to a page about tweening the size of Gui Objects.
I hope this helped! Please comment if there is anything you're wondering or something that isn't working.
6 comments
Hey! The frame doesn't seem to reduce it's size and the animation doesn't seem to play, is there anything wrong with what I made? I put my frame and also, there's Udim2 but it should be UDim2, can't seem to fix it
I mean I tried changing the UDim2 back and forth (capital letter for D and lowersized) or tried changing my Frame or something, but it still doesn't work
Yes of course sorry, it should be UDim2.new()
Do you get any errors?
I updated the script after trying it myself. Now this version works for the gui, just make sure you set the path of the variable correctly with all names and such. I don't know why your animation doesn't work though. Nothing happened when I tried and I even printed ananimEtrack.IsPlaying to see if it was playing, and it returned true, so I don't know what's wrong
It only works for an animation that you created, I thinnk.