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

How do I stop a humanoid getting hurt when fire is doused out?

So I followed the tutorial in the ROBLOX Wiki: http://wiki.roblox.com/index.php?title=Lighting_Parts_on_Fire I feel like I wasn't satisfied with my script, so I edit it so the humanoid who touches the Lava part will get hurt in real-time. However, If the fire on the person is doused out, it will still hurt the humanoid until it dies. I've added something on line 10 that if it's destroyed, it will stop hurting the humanoid, but that doesn't work.

firePart = game.Workspace.Lava
waterPart = game.Workspace.Water

function imonfire(part)
	print(part.Name .. " is on fire!")
	local fire = Instance.new("Fire")
	fire.Parent = part
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	repeat
		if fire:Destroy() == true then return end
		wait(1)
		humanoid.Health = humanoid.Health - 1
	until humanoid.Health == 0
end

firePart.Touched:connect(imonfire)

function water(part)
	local fire = part:FindFirstChild("Fire")
	if fire then
		print(part.Name .. " is not on fire anymore!")
		fire:Destroy()
	end
end

waterPart.Touched:connect(water)

Sorry if this doesn't make any sense.

2 answers

✓ Accepted answer

Hello there! What the green developer said was true, but it doesn't solve your problem. I will be helping you today with a simple fix.

First you want to add a script into ServerScriptService. This will be like making leaderstats. Call the script anything you want and put this code in;

game.Players.PlayerAdded:connect(function(player) --When Player joins
	
	local PlayerStatus = Instance.new("Folder") --A place to store player status
	PlayerStatus.Name = "PlayerStatus"
	PlayerStatus.Parent = player

	local Burning = Instance.new("BoolValue")
	Burning.Name = "Burning"
	Burning.Value = false
	Burning.Parent = PlayerStatus

	local BurnDmg = Instance.new("NumberValue")
	BurnDmg.Name = "BurnDmg"
	BurnDmg.Value = 1
	BurnDmg.Parent = PlayerStatus
end)

Now we have a new Burning status and a damage status!

Now time to edit your script;

local firePart = game.Workspace.Lava
local waterPart = game.Workspace.Water
 
firePart.Touched:connect(function(Hit)
	local Burning = Hit.Parent:WaitForChild("PlayerStatus").Burning.Value 
	local BurnDmg = Hit.Parent:WaitForChild("PlayerStatus").BurnDmg.Value
	if Burning = false then
		Burning = true --Make sure the player is burning
		BurnDmg = 1 --For repeats
		print(part.Name .. " is on fire!")
        	local fire = Instance.new("Fire")
        	fire.Parent = Hit.Parent.Parent:WaitForChild("Torso")
        	local humanoid = Hit.Parent:FindFirstChild("Humanoid")
		while true do
			wait(1)
			humanoid.health = humanoid.health - BurnDmg --TAKES DAMAGE
			if humaoid.health = 0 then
				Burning = false
				BurnDmg = 0
				fire:Destroy()
			end
		end
	end
end)
 
waterPart.Touched:connect(function(Hit)
	local Burning = Hit.Parent:WaitForChild("PlayerStatus").Burning.Value
	local BurnDmg = Hit.Parent:WaitForChild("PlayerStatus").BurnDmg.Value
	print("What you need to say")
	if Hit.Parent:FindFirstChild("fire") then
		Burning = false
		fire:Destroy()
		BurnDmg = 0 
	end	
end)

This is a lot of work but you get the idea. This will solve your problem, now the script probably does have some errors or stuff you don't want but you can remove them and solve the errors (I wrote everything here in rush). Anyway thanks for reading and if this helped you or gave you and idea (which is still helping ) then please Upvote and accept the answer!

1 comment

0

Thank you!

break will end the current while or repeat thread, you could also use repeat until instead, but an example of break is

local startingtick = tick()
while true do
	if (tick() - startingtick) > 5 then
		break --this will break the while true do loop after 5 seconds
	end
	wait()
end

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