Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Delay for pressing E on a tool + GUI?

Asked by 3 years ago

Hello! I'm making a tool and it plays an animation when pressing E. How can I set a custom delay and make a gui to show that delay?

When I press E, I want the player to have a 5 second delay to press E once again, and show in a gui a second delay or a bar that decreases (Like you'd see in games like Blox Fruit)

Here's the script for my E script (inside the tool)

01local player = game.Players.LocalPlayer
02local Tool = script.Parent
03 
04local mouse = player:GetMouse()
05 
06local UserInputService = game:GetService("UserInputService")
07local RunService = game:GetService("RunService")
08 
09repeat wait(1) until player.Character
10 
11local character = player.Character
12local humanoid = character:WaitForChild("Humanoid")
13 
14local AnimE = Instance.new("Animation")
15AnimE.Name = "AnimE"
View all 25 lines...

2 answers

Log in to vote
0
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.

01local player = game.Players.LocalPlayer
02local Tool = script.Parent
03 
04local UserInputService = game:GetService("UserInputService")
05local RunService = game:GetService("RunService")
06 
07local debounce = false -- New variable
08local waitTime = 5 -- New variable
09 
10local character = player.Character or player.CharacterAdded:Wait()
11local humanoid = character:WaitForChild("Humanoid")
12 
13local AnimE = Instance.new("Animation")
14AnimE.Name = "AnimE"
15AnimE.Parent = script.Parent
View all 28 lines...

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.

01local player = game.Players.LocalPlayer
02local Tool = script.Parent
03 
04local UserInputService = game:GetService("UserInputService")
05local RunService = game:GetService("RunService")
06 
07local debounce = false -- New variable
08local waitTime = 5 -- New variable
09local frame = player.PlayerGui:WaitForChild("ScreenGui").FrameToTween -- Set this path to your Frame
10 
11local function debounceToFalse(didComplete) -- New function
12    if didComplete then
13        debounce = false
14    else
15        print("Something went wrong")
View all 44 lines...

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.

0
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 qMrSpooky 20 — 3y
0
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 qMrSpooky 20 — 3y
0
Yes of course sorry, it should be UDim2.new() Spjureeedd 385 — 3y
0
Do you get any errors? Spjureeedd 385 — 3y
View all comments (2 more)
0
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 Spjureeedd 385 — 3y
0
It only works for an animation that you created, I thinnk. qMrSpooky 20 — 3y
Ad
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

Try this

01local player = game.Players.LocalPlayer
02local Tool = script.Parent
03 
04local mouse = player:GetMouse()
05 
06local UserInputService = game:GetService("UserInputService")
07local RunService = game:GetService("RunService")
08 
09repeat wait(1) until player.Character
10 
11local character = player.Character
12local humanoid = character:WaitForChild("Humanoid")
13 
14local AnimE = Instance.new("Animation")
15AnimE.Name = "AnimE"
View all 35 lines...
0
This fixed 80% of my problems. Question is, how do I put that delay to display in a GUI? qMrSpooky 20 — 3y
0
Make a Gui and make a Timer for 3 seconds and make that fire when the delay is happening MattVSNNL 620 — 3y

Answer this question