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

How do I return "name = value", but it not being a string?

Asked by
Protall 10
10 years ago
local TweenPart = require(game:GetService("ServerScriptService"):findFirstChild("PartTweeningModule"))
local add = require(workspace:WaitForChild("SourceScript"))
local ds = game:GetService("DataStoreService"):GetDataStore("playerData")

game:GetService("Players").PlayerAdded:connect(function(player)
    playerData = {
        stats = add.instance("stats", "Model", player);
        bounty = add.commonInstances.value("reputation", "IntConstrained", 0, player:WaitForChild("stats"), 5000, 0);
        race = add.commonInstances.value("race", "String", "", player:WaitForChild("stats"));
        faction = add.commonInstances.value("faction", "String", "Citizen", player:WaitForChild("stats"));
        money= add.commonInstances.value("money", "Int", 0, player:WaitForChild("stats"));
        lvl = add.commonInstances.value("level", "Int", 1, player:WaitForChild("stats"));
        exp = add.commonInstances.value("exp", "Number", 0, player:WaitForChild("stats"));
        inv = add.instance("Inv", "Model", player);
    }

    returnedData = {}

    local function insertByName(value, name)
        return {name = value}
    end 

    local function updateReturnedData()
        for i,v in pairs(returnedData) do
            table.remove(returnedData, i)
        end
        for i,v in pairs(playerData) do
            if string.match(tostring(v.Name), "Value") ~= nil then
                table.insert(returnedData, insertByName(v.Value, v.Name))
                print(returnedData[v.Name])
            end
        end
    end

    coroutine.resume(coroutine.create(function() while true do wait(.03)
        updateReturnedData()
    end     
    end))

    player:WaitForChild("PlayerGui")
    player:WaitForChild("stats")

    local dataValues = ds:GetAsync(player.Name.."playerData")
    print("hi")
end)

"add" is a module script in workspace that returns a table with components instances and commonInstances, it has no problems adding the values into the player

big chunk of script only thing it outputs is "hi"

i think the problem is in the insertByName function and it's not returning {name = value} in a usable way and i'm not getting output because i'm calling the function in a coroutine

please tell me what i've done wrong

EDIT : I had to add something in a function that i edited after i made this post

Answer this question