Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I create a String from a leaderstat Inventory?

Asked by 3 years ago
Edited 3 years ago

So what I'm trying to do is detect a certain item in a leaderstats inventory (sound code) to then play said sound to the whole server.

Ive tried to search for it in leaderstats but I don't know if i wrote my code wrong or this isn't the way to do it

local players = game:GetService("Players")

local stats = {
    {"Cash", 20000},
    {"Items", 0},
    {"Inventory", nil} --Right here
}

players.PlayerAdded:Connect(function(player)
    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player
    for i,v in pairs(stats) do
        local statType = "IntValue"
        local name = v[1]
        local value = v[2]
        if type(value) == "boolean" then
            statType = "BoolValue"
        elseif type(value) == "string" then
            statType = "StringValue"
        elseif value == nil then
            statType = "Folder"
        end
        local stat = Instance.new(statType)
        stat.Name = name
        if value then stat.Value = value end
        stat.Parent = folder
    end
end)





Just to clarify this script is not my attempt to find the item

0
Where is the script showing your attempt to find the item then? Knowing what you have tried already would be helpful. Sparks 534 — 3y

Answer this question