String value equals 2 strings at same time

I’m making an npc pathfinding system and it is very dependent on a string value telling it where it is. I made a function that calculates it’s possible locations but I’ve somehow managed to equate two strings to the same value.

When I print this line of code (above) I recieve this result (below)

There is only one npc.npcLocation value in the game and notice how it prints at the exact same time and on the exact same line. To further confirm that the string equaled two different values I did this.

When I print this line of code with a concatenation (above) I get this result (below)

Still the same time and line.
I’ve looked at my code for hours trying to find out how to fix this but I just can’t come to a conclusion

Below is the code:

local pathFindingParts = {
	["Part1"] = {
		Object = "PfPart1"; --name of object in Workspace
		Branch = {"Part2"}; --name of possible locations to go after
	["Part2"] = {
		Object = "PfPart2";
		Branch = {"Part1"};
local Thread1 = coroutine.create(function()
	while true do
		local success, error = pcall(function()
			for _, tycoon in pairs(game.Workspace.GameContent:GetChildren()) do
				if #tycoon.Pathfinding.Npcs:GetChildren() ~= 0 then --checks if tycoon has npcs
					for _, npc in pairs(tycoon.Pathfinding.Npcs:GetChildren()) do
					for PfPart, PfPartData in pairs(pathFindingParts) do
						if npc.npcLocation.Value == PfPart then --matches current npc position with dictionary key
							local npcDestination = PfPartData.Branch[math.random(1, #PfPartData.Branch)] -- randomizes index to get next random destination
							for PfPart2, PfPartData2 in pairs(pathFindingParts) do
								if PfPart2 == npcDestination then -- matches destination with key to get object from dictionary
									npc.npcLocation.Value = PfPart2
									print(npc.npcLocation.Value.."aaa") -- somehow 2 values at the same time??
									npc.Humanoid:MoveTo(tycoon.Pathfinding[PfPartData2.Object].Position) -- moves npc to location

	if not success then

Can someone please tell me how I have two strings equal the same value? How can this stuff happen and how can I fix it?

I can’t read this very well, the better option is probably to take a screenshot of the first half of your code in the script editor (in studio), then paste the picture here so the indentations and formatting are correct, it’s very hard to see your code for what it really is right now.

Keep the bottom half of your post’s code, but screenshot the first half (from studio, then upload it here). If you try to screenshot all of your code, the image will probably end up being too small to read (unless you can manage to fit it all perfectly)

If I can visualize your code, I’ll have an easier time trying to solve your problem.

Okay, devforum finally let me do it all at once. It’s always buggy for me :confused: But it’s all there now.

i guess the problem comes because its a for loop so when you change a value in for loop it changes according to the table given example if you had a table with apple and banana and you write this

for i,v in pairs(table) do
   yourstringvalue.Value= v

it will print apple and then banana because it loops two times

I figured it out, turns out right after it changes the value it goes back and runs the for loop again this time with the different value and immediately changes the value back.