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

Creating a script that would move a part from a string value?

What I got so far but I'm stuck can you please help me?

Setting StringValues To Parts Position

game.ReplicatedStorage.Broken.Position.Value =tostring(game.Workspace.CamPart.Position)

and I can't get the part to move to that's strings value.I thought this would work but it didn't.

game.Workspace.CamPart.Position = tostring(Vector3.new(game.ReplicatedStorage.Broken.Value.Value))

Do you know what I can do to fix this problem?

2 answers

✓ Accepted answer

You can use string patterns to make this pretty brief, though a tad dense.

-- [^,] means "not a comma"
-- [^,]+ means "one or more not-commas"
-- ([^,]+) means "this is one of the return values"
-- ^ means "from start of string" (don't start from the middle)
-- $ means "'till end of string" (don't stop before the end)
local sx, sy, sz = value:match("^([^,]+),([^,]+),(^,]+)$")

sx and sy and sz are strings not numbers, but that's OK because Vector3.new will convert them to their numeric form for us:

camPart.Position = Vector3.new(sx, sy, sz)

As an added bonus, you can write it all as one quite dense line:

camPart.Position = Vector3.new(value:match("^([^,]+),([^,]+),(^,]+)$"))

Never mind i found a way.

local example = game.ReplicatedStorage.Broken.Value.Value;

local coord = {};

for num in string.gmatch(example, "[%d%.]+") do


    table.insert(coord, tonumber(num));

end;

local v3 = Vector3.new(unpack(coord));

game.Workspace.CamPart.Position = v3

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