Help with splitting string

Hello, I am making a snowball game and I am struggling with a voting system.

I need help splitting a string so the votes and the name of the map can be seperated, here is my code:

(chosen map1 is the first chosen map, the number is the amount of votes)

local split1 = string.split(chosen1 .. " ","%s+")


I tried splitting it up, then printing the second part which is the value, but it just prints “nil”. I tried with the 1st part of the split string, but it printed the name of the map and the amount of votes. How can I fix this?

string.split doesn’t use the C string formatting. It just directly accepts the substring used to split it.

1 Like

You’re concatenating two variables, and then want to split them to receive the two variables as a table instead? Could you not define a table {chosen1, voting.Pad1Holder.VoteDisplay.Votes.Value}?

Your immediate problem is you should be using " " as the separator if you want to split by spaces. If you split something and the full string ends up in index 1 of the returned table, the string didn’t contain the separator you wanted to split by.

Lua’s search patterns aren’t supported in the string library function split().