Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Hypgnosis 186
6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by
PlaasBoer 275 Moderation Voter
6 years ago
Edited 6 years ago

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
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 Hypgnosis 186 — 6y
Ad

Answer this question