Having trouble with string splitting

i’m trying to make a dress up game, there are custom meshes and i’m currently testing with skirts, it is supposed to save the outfit in a string like this

!Accessory type: Color1R, Color1G, Color1B;Color2R, Color2G, Color2B;Color3R, Color3G, Color3B;Color4R, Color4G, Color4B;Color5R, Color5G, Color5B:Name of the accessory

so basically the"!" divides every item, the “:” divides in three part the accessory name , colors, and name of the accessory the “;” divides the 5 colors of the accessory and the ", " divides the colors RGB.

i don’t want to use different string for each cause the player has to be able to use as many accessories as he wants

i don’t know how to check if the player has already a skirt on though, i tried with this so far

``
local Message = script.Parent.Parent.Parent.Parent.leaderstats.Outfit.Value
local SplitMessage = string.split(Message, “!”)
local AssetInfo = string.split(SplitMessage, “:”)
local Type, coloring, nameof= AssetInfo[1], AssetInfo[2], AssetInfo[3]
if Type== “Skirt” then
AssetInfo= " "
end
Message=Message…"!Skirt:1,1,1;1,1,1;1,1,1;1,1,1;1,1,1:SkirtTest"

``
with this i’m trying to detect if the player has a skirt on and delete the string part with it so the script can add a line for the new skirt accessory

This is quite complicated method for making an Outfit system

Make sure the Message variable is not nil

Also your script have wrong spaces

Also type == "Skirt" then is wrongly misplaced

I will explain what it is

When you spilit them, the 1st string will be "Accessory type: Skirt" not "Skirt"

Try debugging

This doesn’t answer your question, but it’s a suggestion to make your life easier: you could just make an outfit a table instead of a string:

local outfit = {
  type = "Skirt",
  colors = { {1, 0, 0}, {0, 1, 0} },
  name = "Something"
}

There are ways to organize your code where you shouldn’t ever need to store this in a StringValue.

But if you must, you can use HttpService:JSONEncode(outfit) to turn it into a string, and JSONDecode(encodedString) to turn it back into a table.

Here’s a short example:

local http = game:GetService("HttpService")

local function printOutfit(outfit)
	print("Outfit:")
	print("  Type:", outfit.type)
	print("  Colors:", outfit.colors)
	print("  Name:", outfit.name)
end

local outfit = {
	type = "Skirt",
	colors = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}},
	name = "SkirtTest"
}

warn("Original outfit:")
printOutfit(outfit)

local outfitAsString = http:JSONEncode(outfit)
-- ^ could put that in a StringValue or whatever...
warn("Converted to a string:")
print(outfitAsString)

-- ...and load it back
local outfitBackAsTable = http:JSONDecode(outfitAsString)
warn("Converted back to a table:")
printOutfit(outfitBackAsTable)

Anyways to answer your question, SplitMessage is a table, i.e. a list “!”-separated strings.

So you can’t call string.split on it directly, you’ll have to loop through it.