Cooldown text not updating in game (works in studio)

I’m working on cooldown UI for abilities in my game. The cooldown text updates every frame based on values stored in a folder inside player, like this:

runService.RenderStepped:Connect(function()
	if not cooldownsFolder then return end
	local now = tick()

	for _, key in ipairs(keys) do
		local slot = abilityBar:FindFirstChild("Slot_" .. key)
		if slot then
			local label = slot:FindFirstChild("CooldownLabel")
			local icon = slot:FindFirstChild("Icon")
			local cooldownFill = slot:FindFirstChild("CooldownFill")

			local cdValue = cooldownsFolder:FindFirstChild(key)
			if cdValue then
				local endTime = cdValue.Value
				local remaining = endTime - now

				if remaining > 0 then
					label.Text = string.format("%.1fs", remaining)
					cooldownFill.Visible = true
					if icon then icon.ImageColor3 = Color3.fromRGB(150, 150, 150) end
				else
					label.Text = ""
					cooldownFill.Visible = false
					if icon then icon.ImageColor3 = Color3.new(1, 1, 1) end
				end
			end
		end
	end
end)

In Roblox Studio the cooldown text updates as expected. But in the game, the cooldown text doesn’t even show up at all.
How can i fix this?

1 Like

check the dev console in game, send a screenshot if there are any warns or errors.

1 Like

there are no errors or warns. on the server the value of the cd changes

Check for errors on the client, since this is a localscript I’d bet the issue is with FindFirstChild, since things tend to load faster on studio than on live servers, this is a very common cause of things not working on live servers but working on studio. If there are any client errors at all send a screenshot. You could also try changing FindFirstChild to WaitForChild if there aren’t any errors on the client just to be sure

1 Like

On studio but not the actual game? It’s probably a problem with some server code. Even if you get a LocalScript error, it will just keep waiting until the next frame and run this code again, so it wouldn’t matter.

But please use WaitForChild for all of these and set them to variables at the top of the script. It is the most efficient. There is also no point of using FindFirstChild if you aren’t checking if it exists or not.

1 Like

it was because of the tick, for some reason it doesn’t work in the game. are there any alternatives?

i fixed bug by using workspace:GetServerTimeNow()

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