So this script is supposed to only teleport the backpacks with an owner value to the part with the same owner value and the owner value == to a players name but when the backpacks teleport the right backpacks go to the right ones but the ones without an owner value also teleport for some reason can someone please help me with this?
task.wait(5)
local players = game.Players:GetChildren()
local parts = game:WaitForChild("Workspace").HouseMap.BackpacksQuest.BackpackParts:GetChildren()
for i,player in pairs(players) do
local randomPart = table.remove(parts, math.random(#parts))
randomPart.Owner.Value = player.Name
end
local backpacks = game:WaitForChild("Workspace").HouseMap.BackpacksQuest.Backpacks:GetChildren()
for i,player in pairs(players) do
local randomBackpack = table.remove(backpacks, math.random(#backpacks))
randomBackpack.Owner.Value = player.Name
end
game.ReplicatedStorage.Values.StoryValues.GetBackpacks:GetPropertyChangedSignal("Value"):Connect(function()
print("triggered")
for _,part in pairs(game:WaitForChild("Workspace").HouseMap.BackpacksQuest.BackpackParts:GetChildren()) do
if part.Owner.Value then
local partPos = part.CFrame
local partName = part.Owner.Value
for _,backpack in pairs(game.Workspace.HouseMap.BackpacksQuest.Backpacks:GetChildren()) do
if backpack.Owner.Value == partName then
backpack.CFrame = partPos
print("PartOwner is "..part.Owner.Value.."and BackpackOwner is "..backpack.Owner.Value)
end
end
end
end
end)