Option to Disable "RunContext" warning

I keep getting this warning in my output, I understand the purpose of it and it’s useful in some cases but not for my case, I know what I’m doing and I should be able to see it once then chose to disable it

Code
local Players = game:GetService("Players")
local localplayer = Players.LocalPlayer

local StarterGui = game:GetService("StarterGui")

local GUI = script.Parent

if not localplayer then
	return
end

if not script:IsDescendantOf(StarterGui) then
	return  
end

local PlayerGui = localplayer:WaitForChild("PlayerGui")
GUI.Parent = PlayerGui
3 Likes

Two possible fixes:

  1. Move the Script with RunContext set to Client in ReplicatedStorage instead so it does not run multiple times

OR

  1. Change the Script with RunContext set to Client to a LocalScript instead so it does not run multiple times
1 Like

I’m not doing any of those, I shouldn’t have to

I set it up the way it is intentionally. My issue is with the warning message, not how many times it runs

You shouldn’t rely on behavior like that, the warning is there because it may cause “unintended behavior”, either currently or in the future. There is no guarantee that the behavior will remain the same going forward.

Additionally for over 99% of developers, that warning is useful for them as they don’t want to rely on unreliable behavior. Adding a setting that almost nobody would use (because better alternatives exist) would use is redundant.

To reliably repeat code, you should look into using either functions or ModuleScripts instead.

I felt like there was a way to disable it, but I guess not. In Studio settings → Diagnosis, you can turn off sound warnings, but surprisingly not much else. I’m sure there are more warnings people would like to not see (example but not Studio-specific I guess), so it could be expanded for sure.
image

Can I ask what Context the warning is in the Output? I assume Studio as it says on the far bottom right. If so, toggling Studio context off would be a temporary yet annoying fix.
image

You’ll have to do this every time you join studio.

1 Like

I don’t think we will do this–you should not be relying on today’s behavior.

Is there some specific reason you are doing it this way instead of this advice?

I’m using LoadAsset on a UI package and placing it in StarterGui. However, during playtesting in Studio, the UI doesn’t get cloned into PlayerGui, so I’m using this as a fix to address the issue.

That wouldn’t work—LocalScripts don’t run in StarterGui.

Why isn’t this recommended? I thought this was exactly how RunContext was supposed to be used?

I understand how RunContext works, I have written my code with safeguards to work exactly as I intend it to be


Here’s another example, I want to preview the UI while I’m working in Studio however I use LoadAsset to get the UI package at runtime

script.Parent:Destroy()

Simply using a regular Script or LocalScript wouldn’t work properly

I still don’t really understand your use case or why it needs to be in StarterGui specifically.

RunContext and StarterXXX don’t really mix, as evidenced by the need for this warning. I don’t think we’ll necessarily change the behavior but even in your use case the script running twice (once in StarterGui, and once when cloned into PlayerGui) and needing to safeguard against that is super surprising.

2 Likes

I thought this was exactly how RunContext was supposed to be used?

That’s my impression, too. The original announcement says:

How does RunContext interact with ‘Starter’ containers?
Starter containers work by cloning their contents locally therefore they will make a copy of any scripts contained in them. If you are using one of the new RunContexts such as Client or Server then both the original scripts and their copies will run. Therefore, you should continue to use the Legacy RunContext or LocalScripts in these containers.

Evidently it discourages the behaviour, but it also clearly describes that Roblox clones the contents, including any scripts. (And I am uncertain what Roblox could reasonably change about this behaviour; I don’t see why relying on this would be a bad idea.)

I can think of these use-cases that would trigger this warning:

  • Having a package in any Starter container that included a “RunContext Server” script that performed one-time-server-setup/configuration. The work-around would be to design the package to be stored in ReplicatedStorage (or Workspace, etc.) and it would install itself to the proper Starter container at runtime.
  • What I and Kitsune were using it for: cleaning up stuff from StarterGui. It’s not hard to move this particular use-case elsewhere (though it’s one more thing to remember, rather than having the script be inside the thing it modifies).
  • Other one-time-configuration that is meant to run on the server. If you aren’t in a Package, you can still use CollectionService, or just point to the instance from the script.

Options to improve the warning message:

  • Only display the warning if the script is still around when it gets cloned for the first time. (This warning would still show up falsely if you intended to do some sort of configuration for each player that entered - though such a script would need something like if not game.Players:IsAncestorOf(script) then return end as line 1, or Kitsune’s if not localplayer then return end. I don’t know how common this is: usually scripts clone this information for each player, rather than relying on Roblox to do it and then configuring the instances after.)
  • Add an option to disable it (perhaps a line at the top of the script, like --!suppress-runcontext-warning)

I am curious if a lot of developers had hard-to-find bugs that occurred by misunderstanding RunContext that this warning helps with? Otherwise, it seems strange to warn about a possibly valid scripting style.

I’m not the one that added it, but I’ve personally seen it many, many, many times :slight_smile: I plan on adding a warning in Explorer for the same thing at some point to catch it earlier.

Pretty simply I do not see this happening.

1 Like