***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)
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 = ...