Hold click to eat/consumed items like Decaying Winter

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    As the title of this thread says, I don’t know how to use the game Decaying Winter’s hold-click system to eat/consume items.

  2. What is the issue?
    The problem is that I tried to do it before and it was a bug. It’s like I pressed and held the click and set the timer to hold the click and let it delete the item I was holding for about 5 seconds. And then when I pressed and held it for less than 5 seconds, it deleted the item I was holding and disappeared.

  3. What solutions have you tried so far?
    I wanted to know if I did something wrong, so I created this thread to ask how to write it.

From what you explained your issue was is that you didn’t check if 5 seconds actually passed. You can measure time passed by creating a local variable with os.time or even tick.

local StartTime = os.time()

task.wait(5) -- This is an example
warn(os.time() - StartTime) -- This will output the number 5

You would then have to go into your script (the hold thingy)

if (os.time - StartTime) < 5 then
 return false -- If our current time minus our last stated time is not greater than 5 second, stop the script
end
2 Likes

I’ll try this method and see if it works. :slight_smile:

I tried it, but I don’t know if it’s right because I did it on the client side of a local script.

Local script in tool

local uis = game:GetService("UserInputService")

local Tool = script.Parent
local equipped = false
local hold = false
local startTime = os.time()
local duration = Tool:GetAttribute("Duration") -- I set to 5 second

Tool.Equipped:Connect(function()
	if not equipped then
		equipped = true
	end
end)

Tool.Unequipped:Connect(function()
	if equipped then
		equipped = false
		hold = false
	end
end)

uis.InputBegan:Connect(function(input, GPE)
	if GPE then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 and equipped then
		hold = true
		while hold == true do
			if (os.time() - startTime) < duration then
				Tool:Destroy()
				return false
			end
			task.wait(duration)
			warn(os.time() - startTime)
		end
	end
end)

uis.InputEnded:Connect(function(input, GPE)
	if GPE then return end

	if input.UserInputType == Enum.UserInputType.MouseButton1 and hold then
		hold = false
	end
end)
1 Like

delete the while loop in the inputBegan event and do this:

local timer = 0
game.GetService("Run Service").Heartbeat:Connect(function(dt)
if not hold then
    timer=0
    return
end
if timer<5 and hold then
    timer+=dt
elseif timer>=5 and hold then
     Tool:Destroy()
end
end)

Check some typo bc im not in studio!

Ok, I’ll try this method and see if it works. :slight_smile:

something like this should work

-- // Declared Services

local UserInputService = game:GetService("UserInputService")

-- // Private Variables

local Tool = script.Parent

local equipped = false
local hold = false

local startTime = nil;
local duration = Tool:GetAttribute("Duration") 


-- // Functions

local function ToolEquipped()
	equipped = true
end

local function ToolUnequipped()
	if equipped then
		equipped = false
		startTime = nil;
	end
end

local function InputBegan(input: InputObject, gPE: boolean)
	if gPE then return end

	if input.UserInputType == Enum.UserInputType.MouseButton1 and equipped then
		startTime = os.time()
	end
end

local function InputEnded(input: InputObject, gPE: boolean)
	if gPE then return end

	if input.UserInputType == Enum.UserInputType.MouseButton1 and equipped then
		if startTime and (os.time() - startTime) >= duration then
			warn("Deleting Tool")
			Tool:Destroy()
		end
	end
end

-- // RBXConnections

Tool.Equipped:Connect(ToolEquipped)
Tool.Unequipped:Connect(ToolUnequipped)

UserInputService.InputBegan:Connect(InputBegan)
UserInputService.InputEnded:Connect(InputEnded)

1 Like

Um, man, it seems to work, but it only deletes the held item when I release the left click. Is there a way to fix this? I want it to reach the duration I set and then it deletes the item.

Try this then

-- // Declared Services

local UserInputService = game:GetService("UserInputService")

-- // Private Variables

local Tool = script.Parent

local equipped = false
local hold = false

local startTime = nil;
local duration = Tool:GetAttribute("Duration") 


-- // Functions

local function ToolEquipped()
	equipped = true
end

local function ToolUnequipped()
	if equipped then
		equipped = false
		startTime = nil;
	end
end

local function InputBegan(input: InputObject, gPE: boolean)
	if gPE then return end

	if input.UserInputType == Enum.UserInputType.MouseButton1 and equipped then
		startTime = os.time()
		task.delay(duration, function()
			if (startTime - os.time()) >= duration then 
				Tool:Destroy()
			end
		end)
	end
end


-- // RBXConnections

Tool.Equipped:Connect(ToolEquipped)
Tool.Unequipped:Connect(ToolUnequipped)

UserInputService.InputBegan:Connect(InputBegan)

Ok it work friend. thank you for helping me :slight_smile:

Now, all that’s left is to hold down the click system and the duration UI bar will appear.

Where can they teach this system? Can you give me some suggestions?

In order to do that you need to use Tweening to tween the size of the Frame based on the the duration. Here is an idea you can use How to create a Slider. You won’t need to use all of it, but this can show you a style you can use. or you can look at this How to make GUI Skill Cooldown

1 Like

Sorry for reply late but thank you :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.