This should probably be a bug report, but i cant post those lol (also my first post).
These warnings seemingly appeared overnight, as my scripts were generating no warnings last night.
Type checking seems to view Models cloned in ReplicatedStorage as a different type then the usual Model type, which causes some really strange warnings.
Below is an example script demonstrating the warnings; I have a Model in ReplicatedStorage that is cloned.
--!strict
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayerService = game:GetService("Players")
-- Service variables
local Rig = ReplicatedStorage.Rig -- Model
-- Module
local Module = {}
local Meta = {
__index = Module
}
-- Types
type CharacterBase = {
Rig: Model,
Player: Player
}
type Character = typeof(setmetatable({} :: CharacterBase, Meta))
-- Public functions
function Module.new(Player: Player): Character
local CharacterRig = Rig:Clone() -- Adding ::Model or :Model fixes the second and third warning, but not the first
CharacterRig.Name = Player.UserId -- Warn here ('number' could not be converted into 'string')
CharacterRig.Parent = workspace -- Warn here ('Workspace' could not be converted into 'ReplicatedStorage')
local Character: Character = setmetatable({ -- Warn here (entire block)
Rig = CharacterRig, -- Type 'Model' from 'DataModel' could not be converted into 'Model' from 'Roblox'
Player = Player
}, Meta)
return Character
end
-- Connections
PlayerService.PlayerAdded:Connect(Module.new)
Line 31-34 give me the weirdest warning:
Even stranger is that moving the model to be cloned under the script itself completely removes all the the type checking warnings. In both contexts the scripts compile just fine.
I’m at a lost as of how to fix these warnings in my game. If anyone has any advice, please do tell.
Repro: bizzare_type_checking.rbxl (73.1 KB) (Scripts are located in ServerScriptService)