I’m trying to find a way to disable then enable a script from a script. What I’ve tried:
game.Workspace.RaceTimer3.StageSigns.PreStageLights.Script.Disabled = true
-- then later in the script:
game.Workspace.RaceTimer3.StageSigns.PreStageLights.Script.Disabled = false
I tried this, but it doesn’t do anything. It just runs the other script and doesn’t disable it. Any help is appreciated! First Roblox DevForum post btw!
local seconds = script.Parent.Parent.Time
local text = script.Parent
local button = script.Parent.Parent.StartRace
script.Parent.Text = seconds.Value -- Makes the text in the TextLabel the same as what is in the "Time" Value under ScreenGui.
text.Visible = false
game.Workspace.RaceTimer3.StageSigns.PreStageLights.Script.Disabled = true
local function Countdown() -- Makes the countdown code into a local function.
for i = 1,seconds.Value do
wait(1)
seconds.Value = seconds.Value - 1
script.Parent.Text = seconds.Value
end
-- Makes the TextLabel countdown from whatever number is in the "Time" Value under ScreenGui.
if seconds.Value == 5 then
game.Workspace.RaceTimer3.StageSigns.PreStageLights.Script.Disabled = false
end
if seconds.Value == 0 then
script.Parent.Text = "GO!"
end
-- When the TextButton value is 0, it becomes "GO!" instead of 0.
wait(1)
if script.Parent.Text == "GO!" then
text.Visible = false
end
end
-- Waits for two seconds, and then makes the TextLabel not visible.
button.MouseButton1Click:connect(function(play)
text.Visible = true
Countdown(play)
end)
-- Makes it so that when you hit the "StartRace" button, it makse the TextLabel visible and plays the "Countdown()" function.
My second script (the one I’m trying to disable/enable):
local seconds = script.Parent.Parent.Time
local text = script.Parent
local button = script.Parent.Parent.StartRace
script.Parent.Text = tostring(seconds.Value) -- Makes the text in the TextLabel the same as what is in the "Time" Value under ScreenGui.
text.Visible = false
game.Workspace.RaceTimer3.StageSigns.PreStageLights.Script.Disabled = true
local function Countdown() -- Makes the countdown code into a local function.
if seconds.Value == 5 then
game.Workspace.RaceTimer3.StageSigns.PreStageLights.Script.Disabled = false
end
for i = seconds.Value,1,-1 do
wait(1)
script.Parent.Text = tostring(seconds.Value)
end
-- Makes the TextLabel countdown from whatever number is in the "Time" Value under ScreenGui.
if seconds.Value == 0 then
script.Parent.Text = "GO!"
end
-- When the TextButton value is 0, it becomes "GO!" instead of 0.
wait(1)
if script.Parent.Text == "GO!" then
text.Visible = false
end
end
-- Waits for two seconds, and then makes the TextLabel not visible.
button.MouseButton1Click:Connect(function()
text.Visible = true
Countdown()
end)
-- Makes it so that when you hit the "StartRace" button, it makse the TextLabel visible and plays the "Countdown()" function.
local PreStageParts = {script.Parent.Part1,script.Parent.Part2,script.Parent.Part3,script.Parent.Part4}
local PreStageLights = {
PreStageLight1 = PreStageParts.PreStagePart1.PointLight,
PreStageLight2 = PreStageParts.PreStagePart2.PointLight,
PreStageLight3 = PreStageParts.PreStagePart3.PointLight,
PreStageLight4 = PreStageParts.PreStagePart4.PointLight
}
function PreStage()
for _, PreStageLight in pairs(PreStageLights) do
PreStageLight.Enabled = true
end
for _, PreStagePart in pairs(PreStageParts) do
PreStagePart.Material = Enum.Material.Neon
end
end
PreStage()
You could make a boolvalue that the script your disabling/enabling can detect to make sure it is supposed to run. Then just change the boolvalue with the other script to make it set it to true or false.
So a BoolValue is a Value (like StringValue which has a value that is a string Example: “test123”) but with a checkmark. If true, the checkmark is selected. If it is false, it is not selected. You could put a boolvalue inside the script that is going to be disabled/enabled and put inside the script a way to check if it is set to true. And then the script that changes the value can just set it to true or false depending on what it is supposed to do.
More Info: BoolValues