SORRY FOR THE LATE RESPONSE
Alright, new idea. Instead of checking if the firebox is touched, let’s check if the humanoid is touched.
Make a script in ServerScriptService and give every player an attribute called “Heat” and set it to 100 or the starting heat value. Since I see you’re setting player’s heat locally, which is very exploitable.
Server script:
local players = game:GetService("Players")
local playersNearFireBoxes = {}
function OnTouched(otherPart: BasePart, player)
-- Checking if the other part is a source of heat
if otherPart:HasTag("HeatSource") then
if not table.find(playersNearFireBoxes, player) then
table.insert(playersNearFireBoxes, player)
end
end
end
function OnTouchEnded(otherPart, player)
-- index is the position of the player in the table
local index = table.find(playersNearFireBoxes, player)
local character = player.Character or player.CharacterAdded:Wait()
local hrp : BasePart = character:WaitForChild("HumanoidRootPart")
if otherPart:HasTag("HeatSource") then
-- Checking if player is touching a different heat source
local isTouchingAnotherSource = false
for _, part in hrp:GetTouchingParts() do
if part:HasTag("HeatSource") then
isTouchingAnotherSource = true
break
end
end
if not isTouchingAnotherSource then
table.remove(playersNearFireBoxes, index)
end
end
end
-- Setting up every player's heat counter
players.PlayerAdded:Connect(function(player)
player:SetAttribute("Heat", 100)
local character = player.Character or player.CharacterAdded:Wait()
local hrp : BasePart = character:WaitForChild("HumanoidRootPart")
-- Adding an extra argument "player" so the functions know what player it is
hrp.Touched:Connect(OnTouched, player)
hrp.TouchEnded:Connect(OnTouchEnded, player)
end)
-- A coroutine to manage all player's heat counters while not interrupting the rest of the script
coroutine.resume(coroutine.create(function()
while true do
for _, player in players:GetChildren() do
if table.find(playersNearFireBoxes, player) then
player:SetAttribute("Heat", player:GetAttribute("Heat") + 1)
else
player:SetAttribute("Heat", player:GetAttribute("Heat") - 1)
end
end
task.wait(1)
end
end))
In this script we are setting every player’s “Heat Counter” and whenever the player’s hrp touches a part, we will check if its a heat source and put him in a table. Whenever the hrp stops touching a part we will remove him from said table.
Give every hitbox the tag “HeatSource” and you’re set.
We will use the table to change every player’s heat counter accordingly. Now for the gui:
local player = game.Players.LocalPlayer
player.AttributeChanged:Connect(function(attribute)
if attribute == "Heat" then
local value = player:GetAttribute("Heat")
-- Adjust the Ui accordingly
end
end)
This will be a simple local script in the player scripts, or player gui, or wherever u want it. Instead of saving the heat value locally where its easily accessed by exploiters, the value is managed by the server and the player will only adjust the Ui, which wont cause any harm.