How can i change the character "." to ":"

simple problem but cant find the solution just like the title i want to change the “.” character to “:” character in this number value

while wait(0.0001) do
	
	if game.Lighting:GetAttribute("DayOrNight") == "Day" then
		
		local formatted = string.format("%.2f", game.Lighting.ClockTime)
		
		script.Parent.Text = formatted.."Am"

	elseif game.Lighting:GetAttribute("DayOrNight") == "Night" then
		
		local formatted = string.format("%.2f", game.Lighting.ClockTime)
		
		script.Parent.Text = formatted.."Pm"

	end
	

	
end
3 Likes

you can use string.gsub() in order to change a ‘.’. to a ‘:’

1 Like

i did, the text becomes “::::” instead of for example 10:00

or maybe i just did it wrong idk

try doing it with string.gsub() again and if you face the same problem then send us the script

alright i will try that thanks for the help so far

I haven’t used string.gsub(), but I think this will work?

while wait(0.0001) do
	if game.Lighting:GetAttribute("DayOrNight") == "Day" then
		local formatted = string.format("%.2f", game.Lighting.ClockTime)
		formatted = string.gsub(formatted, "%.", ":") -- Replacing "." with ":"
		script.Parent.Text = formatted.."Am"
	elseif game.Lighting:GetAttribute("DayOrNight") == "Night" then
		local formatted = string.format("%.2f", game.Lighting.ClockTime)
		formatted = string.gsub(formatted, "%.", ":") -- Replacing "." with ":"
		script.Parent.Text = formatted.."Pm"
	end
end

Just an fyi, this hasn’t been tested.

thats my script that has gsub and it changes the text to “:::::Am”

while wait(0.0001) do
	
	if game.Lighting:GetAttribute("DayOrNight") == "Day" then
		
		local formatted = string.format("%.2f", game.Lighting.ClockTime)

		local changedchar = string.gsub(formatted, ".", ":")

		script.Parent.Text = changedchar.."Am"

	elseif game.Lighting:GetAttribute("DayOrNight") == "Night" then
		
		local formatted = string.format("%.2f", game.Lighting.ClockTime)
		
		local changedchar = string.gsub(formatted, ".", ":")
		
		script.Parent.Text = changedchar.."Pm"

	end
	

	
end

welp i dont know how that worked why does putting % in front of the “.” make it work anyways thanks for th ehlp

while wait(0.0001) do
	
	if game.Lighting:GetAttribute("DayOrNight") == "Day" then
		
		local formatted = string.format("%.2f", game.Lighting.ClockTime)

		local changedchar = string.gsub(formatted, "%.", ":")

		script.Parent.Text = changedchar.."Am"

	elseif game.Lighting:GetAttribute("DayOrNight") == "Night" then
		
		local formatted = string.format("%.2f", game.Lighting.ClockTime)
		
		local changedchar = string.gsub(formatted, "%.", ":")
		
		script.Parent.Text = changedchar.."Pm"

	end
	

	
end

try this

1 Like

Some matching functions like string.gsub use pattern strings which have special “magic” characters that you might need to escape (like “.” in your case)

You can read more here if you’re interested: https://www.lua.org/pil/20.2.html

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