How to calculate the time passed from one function to the other?

The title of the topic kinda explains what im trying to do.
I want the player to hold the left mouse button 2 sec. In my current script, it wont print the third print statement:

local HOLD_TIME = 2
local currentTime = os.time()
local RunService = game:GetService('RunService')

local canThrow = false

mouse.Button1Down:Connect(function()
	if isEquipped() then
		canThrow = true
		currentTime = os.time()
		print("Can throw")
	end
end)

mouse.Button1Up:Connect(function()
	if canThrow then
		print("Nu die ene lijnen")
		if currentTime - os.time() >= HOLD_TIME then
			local camPos = workspace.CurrentCamera.CFrame.Position
			local direction = (mouse.Origin.Position - camPos).Unit
			tool.Throw:FireServer(mouse.Hit.Position, direction)
			print("throw") -- this wont run
		end
	end
end)

this is a snippet of my code

1 Like

os.time()-currentTime

Otherwise the difference will be negative, since the current time is greater than the old time.

2 Likes

ooh okay thanks, I will reply later with an update

1 Like

This worked, my fault for going to the forums to quick. Def something i couldve figured out on my own but thanks!

1 Like

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