StudioService ActiveScript always returns nil

Hello devs!

I’m making a plugin and I need to know the script the user is editing.
I found this: StudioService | Roblox Creator Documentation
I just copy pasted the example and it doesn’t work.
Script:

local startTime = os.time()
local activeScript
local function onActiveScriptChanged(newActiveScript)
	print(newActiveScript)
	if newActiveScript ~= activeScript then
		local deltaTime = os.time() - startTime
		print(("You edited %s for %d:%2.d"):format(activeScript.Name, math.floor(deltaTime / 60), deltaTime % 60))
	end
	startTime = os.time()
	activeScript = newActiveScript
end
game:GetService("StudioService"):GetPropertyChangedSignal("ActiveScript"):Connect(onActiveScriptChanged)

print(newActiveScript) always prints nil, do you have any ideas why is this happening?

2 Likes

Bumping! I have the same issue currently.

EDIT: Solved the issue! You need to directly address RunService.ActiveScript like so:

function OnActiveScriptChanged(Script)
	print(game:GetService("StudioService").ActiveScript)
end

game:GetService("StudioService"):GetPropertyChangedSignal("ActiveScript"):Connect(OnActiveScriptChanged)

Hopefully, this helps anyone with a similar issue!

Thanks!
I discovered the solution already, I forgot to put it here.
But then it’s documented wrong. I hope roblox fixes the issue!

1 Like