Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I fix my temperature system?

***Hello, I'm currently making a project that has a temperature system and am nearly there at cracking it. I just can't figure out why it's not working. I'm using on touch in parts so when the character walks into a different zone with a different temperature, depending on the zone it will either cool down the player or heat up the player


**Here is my script that regulates the temperature for the character (your body heat and what regulates it) **

local functions = script.Parent.Parent:WaitForChild("Functions")
local values = script.Parent.Parent:WaitForChild('Values')
local config = script:WaitForChild('Configuration')
local temp = values:WaitForChild("temperature")
local wtemp = config:WaitForChild('wtemp').Value
c = 0
while true do
	wait(0)
if c == 0  and temp.Value < wtemp then
		c = 1
repeat
	wait(0.3)
	temp.Value = temp.Value + 1
until temp.Value == wtemp or temp.Value > wtemp
c = 0
elseif c == 0  and temp.Value > wtemp then
		c = 1
repeat
	wait(0.3)
	temp.Value = temp.Value - 1
until temp.Value == wtemp or temp.Value < wtemp
c = 0
end
end

**Here is the first script I tried for making **

local ps = game:GetService("Players")
function onTouch(hit)
local pc = hit.Parent
local pn = pc.Name
local p = ps:WaitForChild(pn)
local pg = p.PlayerGui
local cg = pg.CoreMenu
local v = cg.Values
local t = v.temperature

repeat
	wait(10 or 9 or 8 or 7 or 6 or 5 or 10 or 9 or 8 or 7 or 6 or 10 or 9 or 8 or 7 or 10 or 9 or 8 or 10 or 9 or 10)
	t.Value = t.Value - 10 or 20 or 30 or 20 or 10 or 10
until 1 == 0

script.parent.Touched:connect(onTouch)
end

**Here is the second script I tried **

local ct = game:WaitForChild('Lighting').ClockTime
atemp = script.temp.Value
btemp = 60
c = 0
while true do
	
	wait(0.3)
	atemp = ct + btemp

function onTouch(part)
local pn = part.Parent.Name
local p = game.Players:FindFirstChild('pn')
local temp = p.PlayerGui.CoreMenu.Values.temperature.Value
while true do
	wait(0)
if c == 0  and temp.Value < atemp then
		c = 1
repeat
	wait(0.3)
	temp.Value = temp.Value + 1
until temp.Value == atemp or temp.Value > atemp
c = 0
elseif c == 0  and temp.Value > atemp then
		c = 1
repeat
	wait(0.3)
	temp.Value = temp.Value - 1
until temp.Value == atemp or temp.Value < atemp
c = 0
end
end
end
end
script.Parent.Touched:connect(onTouch)

3 comments

0

p.s - the temperature regulator works just fine, it's just the temperature changing that isn't working

0

This might not have anything to do with it, but the second script line12 : local p = game.Players:FindFirstChild('pn') the 'pn' in the FindFirstChild isn't going to look for the playername, but for a player named pn

0

how is the first script you tried supposed to work?

1 answer

The problem in the second script (third code block) is at line 13, you are copying the value of the object instead of getting a reference to the object

Line 13

 local temp = p.PlayerGui.CoreMenu.Values.temperature.Value

the variable temp is of type int, not an object, change it to


local temp = p.PlayerGui.CoreMenu.Values.temperature

and anytime you want to change the value, just remember to call

temp.Value = ...

This discussion is preserved as it was. New answers, comments, and votes are closed.