Expected Behavior
Incorrect warnings get in the way and distract from the correct warnings because if I get used to ignoring the incorrect warnings, I won’t pay attention to the correct ones.
Is the message consider changing it to local saying to convert c into an upvalue like you did, so that it can be used on line 12?
I believe @rogeriodec_games’s issue is that the warning Global ‘c’ is only used in the enclosing function defined at line 2; consider changing it to local
doesn’t really make sense here, since the global c is used outside it’s enclosing function b, rather than the anonymous callback function for PlayerAdded (well, it’s used in both, but the issue is that it’s defined inside the scope of b and is trying to be used outside of it).
I get the warnings only when the functions are inside Players.PlayerAdded:Connect( function(Player).
local Players = game:GetService("Players")
Players.PlayerAdded:Connect( function(Player)
local function a()
local function b()
function c()
-- anything...
end
c()
end
end
c()
end)
W003: (5,13) Global ‘c’ is only used in the enclosing function defined at line 2; consider changing it to local
But if outside PlayerAdded:Connect…
--local Players = game:GetService("Players")
--Players.PlayerAdded:Connect( function(Player)
local function a()
local function b()
function c()
-- anything...
end
c()
end
end
c()
--end)
Because in this case adding a local definition for c would need to happen at the top level, which is approximately equivalent to a local. Adding a local in this case doesn’t make code more robust - the reason why this warning exists is that if c references something like Player object you may see subtle issues in the code due to conflating state from multiple callback calls. When it’s at the top level, it doesn’t matter because the code is executed once, so we don’t warn.
It should stay up. It’s good that OP didn’t firstly assume that it was a bug, but rather user error, hence the first topic being in #help-and-feedback:scripting-support . It didn’t look like the replies were too helpful therefore had to assume it was a bug, luckily everything has been cleared up. Future readers may assume similar in the future therefore this topic should be available to them.