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

How can I fix this block of code from freezing the game? (easy for experienced)

I'm extremely new to scripting. I've been messing around and challenging myself to script certain stuff. Below is the code block, and I've commented on the block that freezes the game.

It's also an edited version of the fire tutorial on the wiki.

wait(1) -- Waits for player to load in.

-- Variables for the lava, users, user HP, and checking to see if player has touched lava.
local Lava = game.Workspace.Lava1
local user = game.Players.LocalPlayer.Character.Humanoid
local userHP = game.Players.LocalPlayer.Character.Humanoid.Health
local userOnFire = Lava.Touched


-- Function that creates the fire effect.
function lightOnFire(part)
	print("Going to light this part on fire:")
	print(part.Name)
 
	local fire = Instance.new("Fire")
	fire.Parent = part
end

userOnFire:connect(lightOnFire) --calls upon function




-- The below code is freezing the game when I attempt to load in.
if userOnFire then
	repeat
		user:TakeDamage(5)
	until 
		userHP <= 0
	else 
		print("I am not on fire!") -- Even without this line, the game freezes.
end

1 answer

✓ Accepted answer

What happens is the program loops continually and never ends now if it had wait() function atleast it can stop the program for that time before it loops again.

You should add wait in after repeat.

if userOnFire then
    repeat
        user:TakeDamage(5)
	wait(0.1) --is 10% of on second
    until 
        userHP <= 0
    else 
        print("I am not on fire!") -- Even without this line, the game freezes.
end

1 comment

0

Thanks for answering! Now, the same block isn't working how I'd like. If you think you can fix it, I've posted another question thread here: https://scriptinghelpers.org/questions/59412/why-does-this-script-damage-me-easy-for-experienced

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