Players:GetPlayers() type checking incorrectly works sometimes

Issue:
Within Roblox Studio’s type-checking/script-analysis Players:GetPlayers() does not return {[number]: Player} and instead returns {[number]: Instance} when Players service is used as a variable. This can confuse developers as GetPlayers always returns Players, this also makes the type checker unaware of Player only functions that can be called on the variables associated with it.

Expected Behavior:
Make Players:GetPlayers() stored as a variable return {[number]: Player} in type-checking. When not stored as a variable script analysis works as intended.

Reproduction:
With the Players service stored as a variable it creates a warning.

local Plrs: Players = game:GetService'Players'
for _:number, Plr:Player in ipairs(Plrs:GetPlayers())do
	local Char: Model? = Plr.Character
	if Char then
		
	end
end

Work Around:
When not stored as a variable, the warning is hidden and script analysis knows the variable is a Player instance.

for _:number, Plr:Player in ipairs(game:GetService'Players':GetPlayers())do
	local Char: Model? = Plr.Character
	if Char then
		
	end
end

Attached Pictures:
image
image

3 Likes

I also have this issue, and it annoys me to no end when I cannot write a script with proper type checking because of this.

Sorry for missing this. We’ll be looking into this now.

It appears this was already fixed some time ago, will mark this as solved.
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.