Not sure what you mean by break the code once a script runs it won’t run again unless your using a while loop or something like that. If you want to destroy the script you should probably reference it by its name for example.
local rs = game:GetService("RunService")
local debounce = false
if rs:IsStudio() then
debounce = true
if debounce == false then
warn("brotest")
end
end
I have a question; why are you using a second if statement to check if debounce equals false when debounce will never be false by this point?
Also, this will not halt execution of the code as it’ll exit the first statement after setting debounce to true, and continue with the rest of the script.
its preventing anything inside of the if debounce == false statement to only be executed when the debounce is false, which it never is. therefore only when he is not in studio he will be warned "brotest". the point is to stop script to continue running code
the script is making it where, when hes in studio while the debounce is false it will warn him, but we never make the debounce be false, therefore its stopping the script from continuing running code…
As @ClockworkSquirrel mentioned, you’re using debounce incorrectly. It’s supposed to be like this:
local debounce = false
local function thing() -- example
if debounce then return end
debounce = true
-- rest of the code
debounce = false
end
See this article by roblox that futher explains debounce. @Aiden_12114 since you marked it as the solution, you should see this too.
That being said, debounce isn’t even the solution for this. You don’t need an extra variable to stop the script when it’s going be the same value all the time anyway. Basically, you’re creating a useless variable, setting the value to always true, and then checking if it’s false.
This code
local debounce = false
if rs:IsStudio() then
debounce = true
if debounce == false then
warn("brotest")
end
end
can be refactored to this
Yea. An empty block. Both scripts will do the same exact thing. I’m trying to explain why the above post is not the solution. It just demonstrates misusage of debounce.
@Aiden_12114 the post I’m replying to, by ClockworkSquirrel, is the actual solution, for the reasons I explained in my other post. Would you mind switching the solution to that so people seeing this thread in the future aren’t mislead by the current solution?