Everytime the codes run for some reason output says that “button” is nil even tho it’s not
local function LoadData()
task.wait(0.4)
for i, v in pairs(Farm.Bought:GetChildren()) do
for x, button in pairs(Buttons:GetChildren()) do
if v.Name == button.Name then
if v.Value == true then
print(button)
LoadButtons(button) --Error Here (Line 67)--
end
end
end
end
end
Use a check. It may because it quite literally doesn’t exist.
local function LoadData()
task.wait(0.4)
if Buttons then
for i, v in pairs(Farm.Bought:GetChildren()) do
for x, button in pairs(Buttons:GetChildren()) do
if v.Name == button.Name then
if v.Value == true then
print(button)
LoadButtons(button)
end
end
end
end
else
warn("Buttons object not found!")
end
end
if its not because of that then show me the LoadButtons function.
Also make sure a button actually exists too.
It’s not because of that. Everything works but not the loadbuttons function.
LoadButtons Function:
function LoadButtons(btn)
if btn:FindFirstChild("CropsToClone") then
local cropstoclone = btn:FindFirstChild("CropsToClone").Value:Clone()
for i, place in pairs(Farm:GetChildren()) do
if place.Name == "Regrow" then
place:Destroy()
end
end
cropstoclone:FindFirstChild("Regrow").Parent = Farm
btn:Destroy()
else
local itemtogive = btn:FindFirstChild("ItemToGive").Value:Clone()
for i, tool in pairs(Player.Backpack:GetChildren()) do
if tool:IsA("Tool") then
tool:Destroy()
end
end
itemtogive.Parent = Player.Backpack
btn:Destroy()
end
end
I don’t know what can be the problem here because everything works perfectly fine. I’ve tried to make it so the function will call only if the Button isn’t nil but it didn’t work