So I need five leaderstats for my game, I am able to load four of them but for some reason, I can't load in the deaths leaderstat. This is my code:
type void = nil
local function addstat(leaderstats: Folder, statname: string, stattype: string): void
assert(leaderstats:IsA("Folder"), `Invalid argument 1 to 'addstat': Expected Folder, got {if typeof(leaderstats) == "Instance" then leaderstats.ClassName else typeof(leaderstats)}`)
assert(typeof(statname) == "string", `Invalid argument 2 to 'addstat': Expected string, got {if typeof(statname) == "Instance" then statname.ClassName else typeof(statname)}`)
assert(typeof(stattype) == "string", `Invalid argument 3 to 'addstat': Expected string, got {if typeof(stattype) == "Instance" then stattype.ClassName else typeof(stattype)}`)
local success: bool, stat: ValueBase = pcall(function()
return Instance.new(stattype);
end)
assert(success, "Error adding stat: Failed to create instance, invalid type?");
assert(stat:IsA("ValueBase"), "Error adding stat: Stat type must be a Value!");
stat.Name = statname;
stat.Parent = leaderstats;
end
game.Players.PlayerAdded:Connect(function(player: Player): void
local leaderstats: Folder = Instance.new("Folder");
addstat(leaderstats, "CryptoCoin", "NumberValue");
addstat(leaderstats, "GemCoins", "NumberValue");
addstat(leaderstats, "Wins", "NumberValue");
addstat(leaderstats, "Kills", "NumberValue");
addstat(leaderstats, "Deaths", "NumberValue");
leaderstats.Name = "leaderstats"
leaderstats.Parent = player;
end)
I want the code to load in all five leaderstats but for some reason it loads in only four leaderstats. There are also no errors in the output widget.
I hope this has been useful.