How can I fix this player detection thing

Hewo !
I made a script (forget the “fuel” part) that is suppose to take humanoid touching reg3, and then damage him. Problem is that I would like it to damage him every seconds, and if the player die, we add “fuel” to the killer, and add him to the table so he can’t be killed more times. In this script, it damage player instantly a lot of time, until its health = 0. Here is the script :

local fuel = game.ReplicatedStorage.Fuel
local part = script.Parent.FireDamageZone
local isDead = {}
local players = game:GetService("Players")
local fuelLoss

game.ReplicatedStorage.Fuel.Changed:Connect(function()
   local min = Vector3.new(part.Position.X-part.Size.X/2, part.Position.Y-part.Size.Y/2, part.Position.Z-part.Size.Z/2)
   local Max = Vector3.new(part.Position.X+part.Size.X/2, part.Position.Y+part.Size.Y/2, part.Position.Z+part.Size.Z/2)
   local FireReg = Region3.new(min, Max)
   if fuel.Value >= 301 then 
   	
   	script.Parent.Humanoid.WalkSpeed = fuel.Value/37.5
   	script.Parent.LowerTorso.Fire.Size = fuel.Value/100
   	script.Parent.UpperTorso.PointLight.Range = fuel.Value/30
   	script.Parent.FireDamageZone.Size = Vector3.new(fuel.Value/60, fuel.Value/60, fuel.Value/60)
   	
   	for _, part in pairs(game.Workspace:FindPartsInRegion3(FireReg,nil,math.huge)) do
   		local plr = players:GetPlayerFromCharacter(part.Parent)
   		local hum = part.Parent:FindFirstChild("Humanoid")
   		if hum then
   			hum:TakeDamage(fuel.Value/10)
   			if hum.Health <= 0 then
   				if table.find(isDead, plr.Name) then continue end
   				table.insert(isDead, plr.Name)
   				fuel.Value = fuel.Value + 75
   			end
   		end
   	end
   	
   	fuelLoss = 1/(2^(fuel.Value/300)/2)

   	wait(fuelLoss)
   	fuel.Value = fuel.Value - 1

   else
   	script.Parent.Humanoid.WalkSpeed = 8
   	script.Parent.LowerTorso.Fire.Size = 2.5
   	script.Parent.UpperTorso.PointLight.Range = 15

   	fuelLoss = 1

   	wait(fuelLoss)
   	fuel.Value = fuel.Value - 1
   end
end)

wait(1)
fuel.Value = fuel.Value - 1
script.Parent.UpperTorso.FireCrackling:Resume()
-- here, the computer already knows what to do when this value is changed

if fuel.Value == 0 then
   script.Parent.Humanoid.Health = 0
   script.Parent.UpperTorso.FireCrackling.Looped = false
   script.Parent.UpperTorso.FireCrackling:Stop()
end

Regarding your issue with the damage killing you instantly, it’s because that there can be more than one Character part touching the Region, you need to make it so when it goes through the region3’s parts, check if they have a humanoid and then check if the parent of the humanoid is not in a table, and if they aren’t, put them in the table and damage, so they get damaged once, and then at the end, empty the table via updating the variable to {}. You can keep the table for checking dead players, remember to also empty that at the end as well after a while.

As for makingit repeat, you can use a while loop to repeat checking and damaging for a certain condition or true to make it infinite, remember to put a wait in the loop or else it’ll crash your Roblox

1 Like