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

How do I convert I string value to a table?

So i have this script where I'm trying to load a players avatar blah blah blah, anyways the point is i don't know how to convert it. this was my attempt to try by ultimately nothing happened

game.Players.PlayerAdded:Connect(function(plr)
	wait(1)
	local tableofitems = {}
	table.insert(tableofitems, plr.stat.char.Value)
	wait(.05)
	for i, v in pairs(tableofitems) do
		print(v)
	end
end)

plr.stat.char.Value is the string with the players avatar in it. When I printed it nothing but a space showed up in output.

1 comment

0

Hmm... is your char.Value a list of things seperated by a space or comma? kinda like [AvatarModel],Name,Score, etc... ?

1 answer

Just a thought, If your Value(s) are inside your plr.stat.char.Value and you seperated them by a comma ( , ) then this code will convert that into a table or list.

Code:

-- this table or list is simply a mockup of values seperated by a comma
local Values = "1,2,Model,blah!,blahA!,blahB!,blahC!"


game.Players.PlayerAdded:Connect(function(plr)
    wait(1)
	local tableofitems = {}
	local expList = Values:split(",")
	for k,v in pairs(expList) do
		table.insert(tableofitems,k,v)
	end
    
    wait(.05)
    for i, v in pairs(tableofitems) do
        print(i," = ", v)
    end
end)

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