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

@OP, could you test the code i gave you?

1 Like

Hmm okay interesting. There’s no function, or way to script it from one script to make the other disable/enable? I feel like there should be a more direct way. Thanks though, I’ll look that up.

2 Likes

Try using an else function, or setting the value to true then wait() and set it to false

1 Like

Oh sorry! I didn’t see your reply with the code before. I’ll test it out.

1 Like

Strange. Now it doesn’t do anything when I click the “Start Race” button I made.

1 Like

Sorry for being late.

Can you show the explorer please? Also, can you show us the script that changes the “Seconds”/“Time” value.

1 Like

Hey, thanks for the response. I decided to do this another way, all inside one script. But if you’d still like to solve it, I can show you the explorer. Knowing how to do this may help later on in the project I’m working on.

1 Like

Alright, i suppose you are going to use an Module Script, right? Also if you have any issues with that, don’t forget to ask for help.

1 Like

Actually, I’m just going to have it all in one server script. There is something I need help with regarding that though if you are open to checking it.

So when I click the “Start Race” button on screen, it doesn’t do anything. Here’s the full script:

local text = script.Parent
local button = script.Parent.Parent.StartRace
lights = game.Workspace["Racing System"].RaceTimer3.StageSigns.PreStageLights.Lights:FindFirstChildOfClass("PointLight")
lightsparts = game.Workspace["Racing System"].RaceTimer3.StageSigns.PreStageLights.Lights:GetChildren()

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

function PreStage()
for _, lightsparts in pairs(lightsparts) do
   
    if lights then
        lights.Enabled = true
    end
end

for _, lightsparts in pairs(lightsparts) do
    lightsparts.Material = Enum.Material.Neon
	end
end


function Countdown() -- Makes the countdown code into a local function.

if seconds.Value == 5 then
	PreStage()
end

if seconds.Value == 5 then

end

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 == 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()
end)
-- Makes it so that when you hit the "StartRace" button, it makse the TextLabel visible and plays the "Countdown()" function.
1 Like

Sorry for being hours late.

Can you show the explorer already? Also, i’am going to try something like that code, but a little different.

1 Like

1 hour later:

It seems that it actually worked, not sure what is the issue you are having.

1 Like

Does that work with pointlights at the same time? That part is what I’ve been struggling with

1 Like

The problem seems to arise when I add the PreStage() function, along with the other code that works with the pointlights/materials. As soon as I added it in the countdown didn’t work when I click the button. Maybe I made duplicate sections of code, or I’m not referring to the right things in the explorer… it’s confusing me.

1 Like

And sorry about that, have been a bit busy with school. I’ll try to send you screenshots of the explorer as soon as I can.

1 Like

Thanks for your help! I can’t believe it. For one thing, I had an if statement that was blank. But the problem was that I didn’t realize that there’s another folder under a folder, so I needed to change the variables. And it works! Thanks very much

2 Likes

U shouldn’t manipulate Gui’s In a ServerScript. U need to use Remotes

1 Like

Whatcha mean? Does it mess it up?

1 Like

Its bad practice and i just makes unnecessary network traffic and will have Input Delay. U wouldn’t want that, using LocaLScripts make the feedback instant.

1 Like

To disable a local script before it can run, create a local script in game.ReplicatedFirst and use WaitForChild() to wait for the other script to replicate, then disable it from there.

If it’s a server script, then disabling the script on the Server will disable it for everyone - and you can’t be sure about whether another server script will exist before it, and that its code will not have run already.
To work around this, try making the server script disabled by default (through it’s Disabled property in Studio), then using code in another script (parented to said script) to manually enable it, then disable it again when needed.

Can you tell use why you need to do this? There are better ways to stop code from running without disabling a script.

Did you try using a ModuleScript for the purpose? You can run its code whenever you want, this would be similar to disabling a script and running it when you need to.

1 Like

To answer your question, it does disable your Script, it just doesn’t terminate the Script’s current thread while it’s running, it only prevents future ones.
This is not your fault, it’s how Roblox’s Script disabling system works. (even though they state in the wiki that disabling a Script terminates the current thread)

However, you shouldn’t rely on the Disabled property for cooldowns, you should instead make your own.

1 Like