Im trying to make this condition work but they both fire for some reason and I cant figure out why
local equation = (itemLocation - slotLocation).Magnitude < 95
if equation then
print(item.Name.." is close to Slot "..slot.Name)
item.Parent = slot
item.Position = slot.Center.Position
else
print("Not close")
end
local equation = (itemLocation - slotLocation).Magnitude <95
if equation then
print (item.Name.."is close to Slot"..slot.Name)
item.Parent = slot
item.Position = slot.Center.Position
elseif not equation then
print ("Not close")
end
Is equation wrapped in a loop? I don’t think your if and else statements are firing at the same time, but instead the equation is still being checked after the position of item is changed. That could explain why it is still printing “not close” after you place the item down.
local function findNearestFrame()
for _, slot in pairs(List:GetChildren()) do
for number = 1,maxSlots,1 do
if slot.Name == tostring(number) then
for _, item in pairs(List:GetDescendants()) do
if item:IsA("ImageLabel") and item.Name ~= "Item" then
local itemLocation = Vector2.new(item.AbsolutePosition.X,item.AbsolutePosition.Y) + item.AbsolutePosition / 2
local slotLocation = Vector2.new(slot.AbsolutePosition.X,slot.AbsolutePosition.Y) + slot.AbsolutePosition / 2
local equation = (itemLocation - slotLocation).Magnitude < 95
if (itemLocation - slotLocation).Magnitude < 95 then
print(item.Name.." is close to Slot "..slot.Name)
item.Parent = slot
item.Position = slot.Center.Position
else
print("Not close")
break -- added this, see if that fixes the problem
end
end
end
end
end
end
end