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

Reading from tables?

Asked by
DevNetx 250 Moderation Voter
8 years ago

I'm using a script for creating and loading characters, but whenever I click Load, I get this error:

Players.Player.PlayerGui.ScreenGui.Frame.LocalScript:24: bad argument #3 to 'Text' (string expected, got table)

wait(0.43)
local module = require(game:GetService('ServerScriptService'):WaitForChild('ModuleScript'))

local characters = {}
table.insert(characters,module.getChars(game.Players.LocalPlayer.UserId))
local pos = 0.15

script.Parent:WaitForChild('Create').MouseButton1Click:connect(function()
    script.Parent:WaitForChild('Create').Visible = false
    script.Parent:WaitForChild('Load').Visible = false
    script.Parent:WaitForChild('CC').Visible = true
    script.Parent:WaitForChild('Name').Visible = true
end)

script.Parent:WaitForChild('CC').MouseButton1Click:connect(function()
    module.createCharacter(script.Parent:WaitForChild('Name').Text,game.Players.LocalPlayer.UserId)
end)

script.Parent:WaitForChild('Load').MouseButton1Click:connect(function()
    script.Parent:WaitForChild('Load').Visible = false
    script.Parent:WaitForChild('Create').Visible = false
    for _, v in pairs(characters) do
    local a =   script.Parent:WaitForChild('Template')
    a.Text = v
    a.Name = v
    a.Position = UDim2.new(0.035, 0,pos, 0)
    a.Visible = true
    pos = pos + 0.10
    end
end)

EDIT: This is what getChars basically does

        local t = {}
        table.insert(t,ds3:GetAsync(player ..'_chars'))
        return t
0
getChars might be returning a table. Since you're inserting a table into `characters`, when you iterate through it at line 22, v is a table. It might be helpful to post what getChars does. XAXA 1569 — 8y
0
GetChars just checks the datastore for player characters and returns a table of all the characters, but I thought Line 22 was supposed to convert each value into a string e.e DevNetx 250 — 8y
0
Line 5 appears to be inserting a table into the characters table. If you're just using the information from the module function, it would be simpler to redefine the characters table. M39a9am3R 3210 — 8y
0
I'm using my module because that's where I have all my functions to save, load, set data ect. But the error is that "v" is a table :( DevNetx 250 — 8y
View all comments (4 more)
0
I added what getChars does DevNetx 250 — 8y
0
@TimeLordSir Is the datastore entry a table? If so, you'll need to iterate through another table on line 24 and 25. Shawnyg 4330 — 8y
0
@Shawnyg Can you give an example please? DevNetx 250 — 8y
0
@TimeLordSir Sure. I'll post it as an asnwer Shawnyg 4330 — 8y

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Here's what I was talking about:

wait(0.43)
local module = require(game:GetService('ServerScriptService'):WaitForChild('ModuleScript'))

local characters = {}
table.insert(characters,module.getChars(game.Players.LocalPlayer.UserId))
local pos = 0.15

script.Parent:WaitForChild('Create').MouseButton1Click:connect(function()
    script.Parent:WaitForChild('Create').Visible = false
    script.Parent:WaitForChild('Load').Visible = false
    script.Parent:WaitForChild('CC').Visible = true
    script.Parent:WaitForChild('Name').Visible = true
end)

script.Parent:WaitForChild('CC').MouseButton1Click:connect(function()
    module.createCharacter(script.Parent:WaitForChild('Name').Text,game.Players.LocalPlayer.UserId)
end)

script.Parent:WaitForChild('Load').MouseButton1Click:connect(function()
    script.Parent:WaitForChild('Load').Visible = false
    script.Parent:WaitForChild('Create').Visible = false
    for _, v in pairs(characters) do
        for i, k in pairs(v) do -- This will go through the table(s) inside of the 'characters' table
                local a =   script.Parent:WaitForChild('Template')
            a.Text = k
            a.Name = k
                a.Position = UDim2.new(0.035, 0,pos, 0)
                a.Visible = true
                pos = pos + 0.10
            end
    end
end)
0
ok I give up with trying to space this. I'm not at home so no Studio, and it's not seeing my tabs correctly #BlameMacs Shawnyg 4330 — 8y
0
12:34:31.007 - Players.Player.PlayerGui.ScreenGui.Frame.LocalScript:25: bad argument #3 to 'Text' (string expected, got table) DevNetx 250 — 8y
Ad

Answer this question