Code Not working

I have this code

script.Parent.MouseButton1Click:Connect(function()
game.Workspace.test.Disabled = false
end)

(The code seems to work as once I select properties on the script as it says that the code is no longer disabled, however, the code doesn’t begin functioning. The script it causes to no longer be disabled is:

while true do
wait(5)
game.Workspace.TEST1.Transparency = 1
wait(5)
game.Workspace.TEST1.Transparency = 0
end

(This code works too).

If you mean by this code:

while true do
wait(5)
game.Workspace.TEST1.Transparency = 1
wait(5)
game.Workspace.TEST1.Transparency = 0
end

script.Parent.MouseButton1Click:Connect(function()
game.Workspace.test.Disabled = false
end)

This is because it is stuck in the loop, use coroutine.

1 Like

If you don’t know how to use corountine then you could use spawn() for it to be easier, like this:

spawn(functon()
   while true do
   wait(5)
   game.Workspace.TEST1.Transparency = 1
   wait(5)
   game.Workspace.TEST1.Transparency = 0
   end
end)

script.Parent.MouseButton1Click:Connect(function()
game.Workspace.test.Disabled = false
end)

Okay, I want the code to be in a loop - the issue was that it doesn’t begin functioning once I use the other code to turn off the disable.

What does this do? Sorry if I sound a bit stupid, I’m new to this so I’m unsure of what function the spawn does, I’m assuming it creates the code or something, but I honestly don’t know.

well, spawn works like another script inside a script.

For example:

--Infinite Loop 1

---Some code -- This won't work since the first loop is not ended yet.

--Infinite Loop2

When using a spawn function:

spawn(function()
    --Infinite Loop 1
    -- The code in here will act like it is under another script 
end)
    ---Some code -- This code will be executed

    --Infinite Loop2 -- The script will run this.