Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Roblox Studio error message says Rank is not a valid member of Folder?

says : Rank is not a valid member of Folder **Line : 13**

23:14:56.361 - Stack Begin 23:14:56.361 - Script 'ServerScriptService.Leaderboard', Line 13 23:14:56.361 - Stack End

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("PlayerStats")

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local Stats = Instance.new("Folder")
    Stats.Name = "stats"
    Stats.Parent = Player
    local Currency = Instance.new("StringValue")
    Currency.Name = "Rank"
    Currency.Value = DataStore:GetAsync(Player.UserId).Rank or "0"
    Currency.Parent = Stats
    local Currency_ = Instance.new("StringValue")
    Currency.Name = "Coin"
    Currency.Value = DataStore:GetAsync(Player.UserId).Coin or "0"
    Currency.Parent = Leaderstats
end)

game.Players.PlayerRemoving:Connect(function(Player)
    DataStore:SetAsync(Player.UserId, {
        ["Rank"] = Player.stats.Rank.Value;
        ["Coin"] = Player.leaderstats.Coin.Value;
    })
end)

1 answer

Your folder arrangement is jumbled up, you're making an extra folder to contain the rank into which is probably why you have that error because it's in the stats folder that is inside leaderstats instead of just leaderstats.

Just scrap the idea of that Stats folder variable because you don't need an extra folder if you have one for leaderstats.

Then, you just adjust in the player removing function where you defined ["Rank"] so it can be fixed with the new changes.

Also, you are calling these datastore calls dangerously, they can error and thus you should utilize pcalls. Here's a tutorial on pcalls if you need it.

This discussion is preserved as it was. New answers, comments, and votes are closed.