I'm trying to make a script that mimics temperature by assigning an IntValue to players so it may measure the amount of heat they receive. As shown in the script below, I'm trying to make it so whenever players are within a certain distance of a heat source, their temperature IntValue increases by one, and when they leave the radius, that increase is removed. I thought what I have would work, but it doesn't work as I thought it would.
local Players = game:GetService("Players")
local player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait()
local char = player.Character or player.CharacterAdded:Wait()
local fire = workspace.Heat
local warmDist = 12
local temp = game.ReplicatedStorage:WaitForChild(player.Name):WaitForChild("Temp")
local inside = false
while true do
wait(1)
local distance = (char.HumanoidRootPart.Position - fire.Position).magnitude
if distance <= warmDist then
inside = true
elseif distance > warmDist then
inside = false
end
end
function updateTemp()
if inside == true then
temp.Value = (temp.Value)+1
elseif inside == false then
temp.Value = (temp.Value)-1
end
end
inside.Changed:Connect(updateTemp)

3 comments
uh maybe try a regular script
u sure men localplayer cant access in script
This script is a local script, the script below is just a normal script. Searching for localplayer in the script below is definitely a problem I didn't notice before, but it should've worked for the localscirpt.