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

This doesn't disable the script as expected, but continues to run, but why?

Asked by 4 years ago

I'm working on a script for a game, and the script won't disable itself as needed for proper functionality in the game. That print message in the end of the if statement ends up happening after the script should be disabled. I have also tried making other scripts disable this one, and checked all other scripts for something enabling it, but it just doesn't disable. It continues to run when it should not.

if Temp.Value >= MeltdownUpperLimit then
    Status.Value = "Meltdown"
    Warn.Value = "Core Meltdown Imminent! Evacuate Now!"
    script.Parent.Parent.Parts.Core.PointLight.Color = Color3.fromRGB(255,0,0)
    script.Parent.Parent.Parts.Core.BrickColor = BrickColor.new("Really red")
    script.Parent.Meltdown.Disabled = false
    script.Parent.ExplosionSounds.Disabled = false
    script.Disabled = true
    print("Bug Test: gamne.Workspace.Core.Scripts.TempIncrementing: Line 133; Script Not Disabled as Expected.") --This is meant to be line 133 in the script.
end

1 answer

Log in to vote
0
Answered by
herrtt 387 Moderation Voter
4 years ago

Disabling the script wont terminate the current thread (the wiki is wrong). If you want the script to end you could return or break if it is a loop (and disconnecting events not sure about this one).

if Temp.Value >= MeltdownUpperLimit then
    Status.Value = "Meltdown"
    Warn.Value = "Core Meltdown Imminent! Evacuate Now!"
    script.Parent.Parent.Parts.Core.PointLight.Color = Color3.fromRGB(255,0,0)
    script.Parent.Parent.Parts.Core.BrickColor = BrickColor.new("Really red")
    script.Parent.Meltdown.Disabled = false
    script.Parent.ExplosionSounds.Disabled = false
    --script.Disabled = true
    return
    --print("Bug Test: gamne.Workspace.Core.Scripts.TempIncrementing: Line 133; Script Not Disabled as Expected.") --This is meant to be line 133 in the script.
end
0
Is there a way to restart a loop after breaking it, though? I would imagine that disabling and enabling the script again causes the loop to run again, but in previous testing this does not happen... AzrefriskDreemurr 8 — 4y
0
Disabling and enabling the script should restart it. You could make a function of the loop and just call it when you feel like starting it. herrtt 387 — 4y
0
Thank you! It works very well! AzrefriskDreemurr 8 — 4y
Ad

Answer this question