Answered by
3 years ago Edited 3 years ago
I suppose you know how to use debounces?
To start I'll add a debounce for you.
01 | local player = game.Players.LocalPlayer |
02 | local Tool = script.Parent |
04 | local UserInputService = game:GetService( "UserInputService" ) |
05 | local RunService = game:GetService( "RunService" ) |
10 | local character = player.Character or player.CharacterAdded:Wait() |
11 | local humanoid = character:WaitForChild( "Humanoid" ) |
13 | local AnimE = Instance.new( "Animation" ) |
15 | AnimE.Parent = script.Parent |
18 | local animEtrack = humanoid:LoadAnimation(AnimE) |
20 | UserInputService.InputBegan:Connect( function (key, gameProcessed) |
21 | if key.KeyCode = = Enum.KeyCode.E and not gameProcessed and not debounce then |
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.
01 | local player = game.Players.LocalPlayer |
02 | local Tool = script.Parent |
04 | local UserInputService = game:GetService( "UserInputService" ) |
05 | local RunService = game:GetService( "RunService" ) |
09 | local frame = player.PlayerGui:WaitForChild( "ScreenGui" ).FrameToTween |
11 | local function debounceToFalse(didComplete) |
15 | print ( "Something went wrong" ) |
19 | local character = player.Character |
20 | local humanoid = character:WaitForChild( "Humanoid" ) |
22 | local AnimE = Instance.new( "Animation" ) |
24 | AnimE.Parent = script.Parent |
27 | local animEtrack = humanoid:LoadAnimation(AnimE) |
29 | UserInputService.InputBegan:Connect( function (key, gameProcessed) |
30 | if key.KeyCode = = Enum.KeyCode.E and not gameProcessed and not debounce then |
33 | frame.Size = UDim 2. new( 0 , 0 , 0 , 50 ) |
36 | UDim 2. new( 0 , 100 , 0 , 50 ), |
37 | Enum.EasingDirection.In, |
38 | Enum.EasingStyle.Linear, |
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.