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
print("check")
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
end
end
end
end
end
end
end
end)
if not success then
print(error)
end
wait(3)
end
end)
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?