I am trying to detect in a server-sided script, and only when executing the game from within Roblox Studio, if the developer pressed the green ‘Run’ button in Roblox Studio.
However it seems that RunService:IsRunMode()
for a server-sided script returns true
, even when using the ‘Play Here’ and ‘Play’ buttons in Roblox Studio.
Is the API documentation for IsRunMode wrong? … Or perhaps not specific enough? … Or could this possibly be a real bug for the ‘Studio Bugs’ sub-forum?
I have done some tests, using nothing more than the baseplate template, and the following server- and client-scripts:
-- Script - placed in ServerScriptService
local RunService = game:GetService("RunService")
print("(S)IsStudio =", RunService:IsStudio())
print("(S)IsRunMode=", RunService:IsRunMode())
print("(S)IsServer =", RunService:IsServer())
print("(S)IsClient =", RunService:IsClient())
print("(S)IsRunning=", RunService:IsRunning())
-- LocalScript - placed in StarterPlayer/StarterCharacterScripts
local RunService = game:GetService("RunService")
print("(C)IsStudio =", RunService:IsStudio())
print("(C)IsRunMode=", RunService:IsRunMode())
print("(C)IsServer =", RunService:IsServer())
print("(C)IsClient =", RunService:IsClient())
print("(C)IsRunning=", RunService:IsRunning())
Using the ‘Run’, ‘Play Here’ and ‘Play’ buttons, results in this output (layout set to be easier to read):
Run
(S)IsStudio = true
(S)IsRunMode= true
(S)IsServer = true
(S)IsClient = false
(S)IsRunning= true
Play Here
(S)IsStudio = true (C)IsStudio = true
(S)IsRunMode= true (C)IsRunMode= false
(S)IsServer = true (C)IsServer = false
(S)IsClient = false (C)IsClient = true
(S)IsRunning= true (C)IsRunning= true
Play
(S)IsStudio = true (C)IsStudio = true
(S)IsRunMode= true (C)IsRunMode= false
(S)IsServer = true (C)IsServer = false
(S)IsClient = false (C)IsClient = true
(S)IsRunning= true (C)IsRunning= true
As can be seen, the server-sided script’s call to RunService:IsRunMode()
always return true
- basically making the IsRunMode()
useless, and not follow what the description at the API documentation page specifies it should do.
Or is there some weird logic, that can explain why it is doing that?
Are there any work-around for this? Perhaps count the number of players when IsStudio=true & IsServer=true, and if that count is zero then “perhaps” it may have been the ‘Run’ button that was pressed in Roblox Studio?