Help to cooldown to pick up Tool

Hello developers, I need help with the script, I want to make a selection of the tool on the E button with a cooldown so that when E is pressed, the cooldown would decrease well, and after 5 seconds the tool would get picked up

script:

local Regions = workspace["RegionSpawn"]
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local count = script.Parent.CountCollect
local char = Players.LocalPlayer.character

local Events = ReplicatedStorage["Events"]
local CollectEvent = Events.Collect

local CollectButton = script.Parent:WaitForChild("CollectButton")

UIS.InputBegan:Connect(function(input)
  if input.UserInputType == Enum.UserInputType.Keyboard then
	if input.KeyCode == Enum.KeyCode.E then
		for i,v in pairs(Regions:GetChildren()) do
			for i,b in pairs(v.BoxesClones:GetChildren()) do
				local mag = (b.Position-char.HumanoidRootPart.Position).magnitude
				if mag <= 5 then
					spawn(function()
						while wait(1) do
							if count.Value > 0 then
								count.Value -= 1
							else
								count.Value += 5
							end
						end
					end)
					if count == 0 then
						CollectEvent:FireServer(b.Name)
					end
				end
			end
		end
	end
end
end)

i think what you’re looking for is this ProximityPrompt | Roblox Creator Documentation

Well, I have my own button that I want to pin

See below there is a cooldown inscription
111

Oh alright then

local Regions = workspace["RegionSpawn"]
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local count = script.Parent.CountCollect
local char = Players.LocalPlayer.character

local Events = ReplicatedStorage["Events"]
local CollectEvent = Events.Collect

local CollectButton = script.Parent:WaitForChild("CollectButton")
local debounce = false

UIS.InputBegan:Connect(function(input)
if debounce == false then
  if input.UserInputType == Enum.UserInputType.Keyboard then
	if input.KeyCode == Enum.KeyCode.E then
        debounce = true
		for i,v in pairs(Regions:GetChildren()) do
			for i,b in pairs(v.BoxesClones:GetChildren()) do
				local mag = (b.Position-char.HumanoidRootPart.Position).magnitude
				if mag <= 5 then
					spawn(function()
						while wait(1) do
							if count.Value > 0 then
								count.Value -= 1
							else
								count.Value += 5
							end
						end
					end)
					if count == 0 then
						CollectEvent:FireServer(b.Name)
					end
                    wait(5)
                    debounce = false
				end
			end
		end
	end
end
end
1 Like

that should give u a cooldown but for the gui u can make it your way

Okay thanks for your time! Have a good day :wink:

1 Like