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

How to separate a string into Data?

I created a save/load script for Parts. Now i have to seperate the data to load it again how whould i do this?

Data format: Name: [Part], Position: [0, 0, 0] , Color: [0, 0, 0] , Material: [Enum.Material.Plastic]

how would you separate this to something like local Name,local Position, local Color and local Material?

I thought about doing something like string.sub

How I store the data:

function generateDataTable(player)
    local dataTable = {} 
    for i,v in pairs(game.Workspace.TestFolder:GetChildren()) do 
        table.insert(dataTable, ("Name: ["..tostring(v.Name).."], Position: ["..tostring(v.Position).."] , Color: ["..tostring(v.Color).."] , Material: ["..tostring(v.Material).."]"))
    return dataTable
end

7 comments

0

It depends on how you`re saving the parts... can you please post the script?

0

I added the script to the question

0

I think the error is on the saving script

0

there is no error i just want to get the saved data separated into pieces

0

I want this: Name: [Part], Position: [0, 0, 0] , Color: [0, 0, 0] , Material: [Enum.Material.Plastic] to be something like this: local Name = ... local Position = ... local Color = ... local Material = ...

0

You don't need to tostring the name, it's already a string.

0

ok but how do i seperate the data

1 answer

✓ Accepted answer

Hello, MageMasterHD!

I think you don't know lots about tables and dictionaries, that I think is what you want to do with your data, so I had to create it:

local dataTable = {} 
for i,v in pairs(game.Workspace.TestFolder:GetChildren()) do 
	table.insert(dataTable, {["Name"] = v.Name, ["Position"] = v.Position, ["Color"] = v.Color, ["Material"] = v.Material}) --Created a Dictonary of the values
end

Now you can do:

dataTable[1]["Name"] --This will give the name of the object 1
dataTable[1]["Position"] --This will give the Vector3 of the object 1 position
dataTable[1]["Color"] --This will give the Color3 of the object 1

By Object 1 i'm telling about the object with index 1 (first object of the for loop)

Useful Links:

https://developer.roblox.com/articles/Table#Dictionaries

Hope this helps

Good Luck with your games

1 comment

0

thx you helped me a lot

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