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 a string into a table?

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:connect(function(msg)
		local msgs = string.gmatch(msg,"%S+")
		for i,v in pairs(msgs) do
			print(v)
		end
	end)
end)

When I do this, I get an error that msgs is a function.

2 comments

0

Just simply remove pairs. ;3

0

Well, that and remove the 'i' also.

1 answer

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        local msgs = string.gmatch(msg,"%S+")
        for v in msgs do
            print(v)
        end
    end)
end)

Edited so that I don't get comments about the deprecated lowercase connect or accessing PlayerService by name.

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