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)