For i, v in pairs() do not working

I don’t know why but on line 3, my function completely stops working, it does everything before it but stops after for loop begins.

script.Parent.Purchase.OnServerEvent:Connect(function(player, item)
	local PurchasableItems = workspace.PurchasableItems
	for i, v in pairs(PurchasableItems:GetChildren()) do
		print(v.Name, item.RecognizedAs)
		if v.Name == item.RecognizedAs then
			for i, e in pairs(player.Backpack:GetChildren()) do
				if e.Name == v.Name and e.Name ~= "HealingPotion" then warn("already has item") return end
			end
			if player.Character:FindFirstChildOfClass("Tool").Name == v.Name and player.Character:FindFirstChildOfClass("Tool").Name ~= "HealingPotion" then warn("already has item") return end
			player.Character.Dabloon.Value -= item.Price
			local boughtItem = v:Clone()
			boughtItem.Parent = player.Backpack
		end
	end
end)

add a print b4 the loop
and get rid of the pairs

Turns out the tools in the PurchaseableItems folder get deleted which is why it never ran.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.