Screen GUI Temperature Change

Hello there!
I’m trying to make a temperature screen Gui that shows the in-game temperature. I’m not sure why it is not working, though. It is supposed to change the text on two screen gui text labels, and the atmosphere density, but it isn’t working. Here’s the script:

local Fog = game.Lighting.Atmosphere
local FogLevel = game.StarterGui.ScreenGui.Frame.Fog
local Temp = game.StarterGui.ScreenGui.Frame.TextLabel

while true do
	wait(30)
	Temp.Text = "Temperature: 76 F 24 C"
	wait(120)
	Temp.Text = "Temperature: 83 F 28 C"
	FogLevel.Text = "Fog Level: Almost None"
	Fog.Density = 0.243
	wait(184)
	Temp.Text = "Temperature: 75 F 23 C"
	FogLevel.Text = "Fog Level: Light"
	Fog.Density = 0.34
	wait(200)
end

You are indexing the wrong labels. Right now, your script changes the Text properties of the instances in the StarterGui. The ones you want to change are in the PlayerGui. The way it actually works is all instances in StarterGui get cloned into the PlayerGui when the player is loaded.

If this is a server script, then you should first name the ScreenGui as something that can be distinguished, such as “WeatherGui”. Then you can loop through all players and change their texts.

If this is a local script, then you shouldn’t be changing the fog on the client to begin with. Change it on the server and fire a remote event to fire an event on the client. Parent this script to the ScreenGui and index the labels as script.Parent.Frame.Fog/TextLabel.

Also, don’t use wait() it isn’t precise and might take a lot longer to resume than you specified. Here’s a simple function you can replace it with:

local heartbeat = game:GetService("RunService").Heartbeat

local customwait = function(t)
    local st = os.clock()
    while (os.clock()-st)<t do heartbeat:Wait() end
end

--use it just as you would with a wait()
customwait(10)
2 Likes