How Can I Disable/Enable A Seperate Script From A Script

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! :smiley:

13 Likes

Is it a local script? (30 chars)

3 Likes

They’re both set to true.

Hope this helps! :+1:

No it’s a regular script. (30 chars)

1 Like

That was probably an spell error, also, i honestly think you have made it reverse. (true, to then false.)

Dear Mj,

try to use if or else functions and can you explain what exactly you are trying to do? using the scripts. Im also working on the issue

Off subject btw, do you have to put “(30 chars)” in your post if it’s under 30 characters every time?

I believe so. :+1:

(30 characterssssss)

1 Like

I mean, you can enable/disable other script, in an script, ahhh, i cannot explain, i will make an GIF/Video instead.

I first declared variables, then put:

game.Workspace.RaceTimer3.StageSigns.PreStageLights.Script.Disabled = true

Then I made a for loop that counts down. And just so you know, time.Value is equal to 5. Here:

for i = 1,seconds.Value do
 wait(1)
 seconds.Value = seconds.Value - 1
 script.Parent.Text = seconds.Value
end

Below that I have some if statements, one of them being the script disabling one that’s not working.
It says:

if seconds.Value == 5 then
	game.Workspace.RaceTimer3.StageSigns.PreStageLights.Script.Disabled = false
end

This is all inside a function. Then at the end I connected the function to MouseButton1Click. Here:

button.MouseButton1Click:connect(function(play)
	text.Visible = true
	Countdown(play)
end)

Then in the other script I’m trying to enable/disable, it’s to make the lights light up and change to neon. Here:

PreStageLight1 = script.Parent.Part1.PointLight
PreStagePart1 = script.Parent.Part1
PreStageLight2 = script.Parent.Part2.PointLight
PreStagePart2 = script.Parent.Part2
PreStageLight3 = script.Parent.Part3.PointLight
PreStagePart3 = script.Parent.Part3
PreStageLight4 = script.Parent.Part4.PointLight
PreStagePart4 = script.Parent.Part4

function PreStage()

PreStageLight1.Enabled = true 
PreStagePart1.Material = Enum.Material.Neon

PreStageLight2.Enabled = true 
PreStagePart2.Material = Enum.Material.Neon

PreStageLight3.Enabled = true 
PreStagePart3.Material = Enum.Material.Neon

PreStageLight4.Enabled = true 
PreStagePart4.Material = Enum.Material.Neon

PreStageLight4.Enabled = true 
PreStagePart4.Material = Enum.Material.Neon
	
end

PreStage()

I just need to find a way to disable/enable the other script from this script I’m showing you.

Can you please show all the script?

My first script:

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):

PreStageLight1 = script.Parent.Part1.PointLight
PreStagePart1 = script.Parent.Part1
PreStageLight2 = script.Parent.Part2.PointLight
PreStagePart2 = script.Parent.Part2
PreStageLight3 = script.Parent.Part3.PointLight
PreStagePart3 = script.Parent.Part3
PreStageLight4 = script.Parent.Part4.PointLight
PreStagePart4 = script.Parent.Part4

function PreStage()

PreStageLight1.Enabled = true 
PreStagePart1.Material = Enum.Material.Neon

PreStageLight2.Enabled = true 
PreStagePart2.Material = Enum.Material.Neon

PreStageLight3.Enabled = true 
PreStagePart3.Material = Enum.Material.Neon

PreStageLight4.Enabled = true 
PreStagePart4.Material = Enum.Material.Neon

PreStageLight4.Enabled = true 
PreStagePart4.Material = Enum.Material.Neon
	
end

PreStage()

Wasn’t its value decreased in the function?

Also:

“play” in actually nil, just do “Countdown()”

Oh okay thanks, you’re right. I changed it to Countdown(), and I’ll put the

if seconds.Value == 5 then
	game.Workspace.RaceTimer3.StageSigns.PreStageLights.Script.Disabled = false
end

before the for loop, so that it will equal it before it decreases by one. Any ideas on how to disable/enable the second script? Thanks again.

Try using these codes:

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()
1 Like

Well, its actually reverse:

image

1 Like

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.

1 Like

Hmmm, I’m not familiar with boolvalues unfortunately. I just started scripting 2 weeks ago. Could you maybe explain how that’d work a bit more?

1 Like

BoolValue is an Value which you can set to true/false, because we call true/false an Boolean.

2 Likes

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

2 Likes