How to make a global cooldown? (i.s. the time will be counted without the player)

Hello! I want make script with save boost with time, but I don’t know how made it.

(if someone didn’t understand what I’m talking about
remember BSS where there is Bubble Bloat for example and when you leave and come back after 30 minutes the 30 minutes is subtracted from the total buff time even if the player is out of the game)

I tried with os.time() but, how to implement it?

If 1x boost = 180s , i need save Nx boost in any Number value and os.time() when player left?

2 Likes

Okay so you want to first save it in a DataStore, I suggest to save a value like so:

UntilTimeOver.Value = os.time() + 30*60 -- + 30 minutes

So basically you add the time to it.

Now when the player leaves you want to save it, then make sure the boost is still valid with:

os.time() < UntilTimeOver.Value

That’s how you are able to do it.

3 Likes

(this is just a more detailed how to do it)Tutorial for those who, like me, were looking for this:

--Data Store Script
 
--Save boost
	local SavedBoosts = Instance.new("Folder")
	SavedBoosts.Name = "SavedBoosts"
	SavedBoosts.Parent = player
	
	local BoostTwitchBloat = Instance.new("IntValue")
	BoostTwitchBloat.Parent = SavedBoosts
	BoostTwitchBloat.Name = "BoostTwitchBloat"
	BoostTwitchBloat.Value = 0
-- Other 
		BoostTwitchBloat.Value = tableOfData["BoostTwitchBloat"]  --We need save this value
--Other
--Saved Boost load	
	--Twitch Bloat
	if BoostTwitchBloat.Value > os.time()  then
		local N = BoostTwitchBloat.Value - os.time()
		print(N) --test
		local A = math.round(N/60)
		print(A) --test
		BoostBloxTv.Value = A
		player.PlayerGui:WaitForChild("Buffs"):WaitForChild("Frame"):WaitForChild("Bloxtv").Visible = true --not necessarily
		player.PlayerGui.Buffs.Frame.Bloxtv.Bloxtv.XBUFF.xbuuf2.Value = A -- not necessarily
		player.PlayerGui.Buffs.Frame.Bloxtv.Bloxtv.XBUFF.Text = "x"..player.PlayerGui.Buffs.Frame.Bloxtv.Bloxtv.XBUFF.xbuuf2.Value -- not necessarily
		player.PlayerGui.Buffs.Frame.Bloxtv.Buff.Size += UDim2.new(0,0,-A * 0.04975,0) -- not necessarily
		
	elseif BoostTwitchBloat.Value < os.time() then
		BoostBloxTv.Value = 0
		
	end 
-- This is just an example, and yes, math.round only gets integers, it's not an ideal script

--Save when player remove
["BoostTwitchBloat"] = os.time() + (player.BoostBloxTv.Value * 60) -- BoostBloxTv.Value have minutes, not second

image

3 Likes

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