Hey! I am trying to disable the script temporarily and the while loop is still going. I tried breaking it, but then it broke the game functions. Is this intentional or a bug of some sort?
Code if needed:
local ServerStorage = game:GetService("ServerStorage")
local PowerService = ServerStorage:FindFirstChild("Power")
while task.wait(0.5) do
workspace.Power.Button.Color = Color3.fromRGB(0,0,0)
PowerService.CurrentPower.Value -= PowerService.PowerBeingUsed.Value/10
if PowerService.CurrentPower.Value >= PowerService.MaxPower.Value/2 then
workspace.Power.Shock.Transparency = 0
else
workspace.Power.Shock.Transparency = 0.7
end
if PowerService.CurrentPower.Value <=0 then
for index, value in pairs(game:GetService("Players"):GetPlayers()) do
local CheckForCharacter = value.Character or value.CharacterAdded:Wait()
local Character = value.Character
value.Character:WaitForChild("ShowPowerStationRestore").Disabled = false
end
print("Hey!")
game.ServerStorage.Power.Gui.CanMessageOff.Value = true
PowerService.PowerBeingUsed.Value = 0
workspace.Power.Button.BillboardGui.Enabled = true
workspace.Power.Shock.DamageScript.Disabled = true
workspace.Power.Shock.Transparency = 1
workspace.Power.Shock.CanCollide = false
script.Disabled = true
end
end
local ServerStorage = game:GetService("ServerStorage")
local PowerService = ServerStorage:FindFirstChild("Power")
while task.wait(0.5) do
if script.Disabled then
return
end
workspace.Power.Button.Color = Color3.fromRGB(0,0,0)
PowerService.CurrentPower.Value -= PowerService.PowerBeingUsed.Value/10
if PowerService.CurrentPower.Value >= PowerService.MaxPower.Value/2 then
workspace.Power.Shock.Transparency = 0
else
workspace.Power.Shock.Transparency = 0.7
end
if PowerService.CurrentPower.Value <=0 then
for index, value in pairs(game:GetService("Players"):GetPlayers()) do
local CheckForCharacter = value.Character or value.CharacterAdded:Wait()
local Character = value.Character
value.Character:WaitForChild("ShowPowerStationRestore").Disabled = false
end
print("Hey!")
game.ServerStorage.Power.Gui.CanMessageOff.Value = true
PowerService.PowerBeingUsed.Value = 0
workspace.Power.Button.BillboardGui.Enabled = true
workspace.Power.Shock.DamageScript.Disabled = true
workspace.Power.Shock.Transparency = 1
workspace.Power.Shock.CanCollide = false
script.Disabled = true
end
end
You all can’t find a simple solution, because your doin while task.wait do, which continuously does the loop Everytime the wait hits ignoring the script.disabled. try doing while true do with a task.wait.
When scripts are destroyed or disabled, any currently running loops will still remain running. This is why scripts can run without a source. If you do not wish for this behaviour change your loop to something such as
repeat
--Code here
task.wait(.5)
until script.Disabled or not script.Parent