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

Reading from tables?

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

8 comments

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.

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

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.

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 :(

0

I added what getChars does

0

@TimeLordSir Is the datastore entry a table? If so, you'll need to iterate through another table on line 24 and 25.

0

@Shawnyg Can you give an example please?

0

@TimeLordSir Sure. I'll post it as an asnwer

1 answer

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)

2 comments

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

0

12:34:31.007 - Players.Player.PlayerGui.ScreenGui.Frame.LocalScript:25: bad argument #3 to 'Text' (string expected, got table)

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