Need feedback on server-sided cooldown that utilizes intvalues

So i just made a function that is entirely server-sided and about cooldowns it works great and unexploitable due to the value changing on server-side, however i still need feedback on how i can improve it and possibly make it better!

function Engine.CreateCD(Player: Player?)
	local __CD = Instance.new("IntValue")
	__CD.Parent = Player
	__CD.Name = "CD"
end

function Engine.ChangeCD(Player: Player?, CD: IntValue?)
	if Player:FindFirstChild("CD") then
		CD.Value = 3
		coroutine.wrap(function()
			   if CD.Value >= 0 then
		         repeat 
			     task.wait(1)
					CD.Value -= 1
				until CD.Value <= 0
				end
		end)()
	end
end
if PLAYER:FindFirstChild("CD").Value <= 0 then
        Engine.ChangeCD(PLAYER, PLAYER:FindFirstChild("CD")) -- Apply cooldown!
		print("Test cooldown") -- prints if intvalue (or cooldown) is below 0 
end

Instead of wasting resources from the usage of a repeat until loop to manually decrease the cooldown value, you could set the cooldown value to tick() and then you can simply use it to check the duration of time that has passed since you set the value by doing tick() - CD.Value.

I heard tick() is deprecated in favor of os.time() should i use it instead?

Well deprecated doesn’t mean you can’t use it anymore, it’s just means that it should no longer be used for newer projects. If you’re looking for an alternative, you could use os.clock() considering it includes milliseconds whereas os.time() does not, someone can correct me if I’ve said a few things that haven’t been entirely accurate.

1 Like