Script returning nil and I have no idea why

I’ve asked many support communities and they’re all telling me my code should work as intended, but it just isn’t! I followed a tutorial directly and their script is exact 1/1 version of mine - and theirs works, but mine doesn’t! Here’s the code:

local tycoon = script.Parent.Parent -- [TYCOON MODEL]

local mainItems = tycoon:FindFirstChild("MainItems") -- [MAIN ITEMS FOLDER]
local values = tycoon:FindFirstChild("Values") -- [VALUES FOLDER]

local buttons = tycoon:FindFirstChild("Buttons")
local purchasedItems = tycoon:FindFirstChild("PurchasedItems")

local objects = {}

mainItems.OwnerDoor.Door.Touched:Connect(function(hit)
	if values.OwnerValue.Value == nil then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			if player:FindFirstChild("HasTycoon").Value == false then
				player:FindFirstChild("HasTycoon").Value = true
				values.OwnerValue.Value = player
				mainItems.OwnerDoor.Title.SurfaceGui.TextLabel.Text = tostring(values.OwnerValue.Value).."'s School"
			end
		end
	end
end)

if buttons then
	for i, v in pairs(buttons:GetChildren()) do
		spawn(function()
			if v:FindFirstChild("Button") then
				
				local newObject = purchasedItems:FindFirstChild(v.Object.Value)
				print(purchasedItems:FindFirstChild(v.Object.Value))
				if newObject ~= nil then
					objects[newObject.Name] = newObject:Clone()
					newObject:Destroy()
				else
					v:Destroy()
				end
				
				if v:FindFirstChild("Dependency") then
					v.Button.Transparency = 1
					v.Button.CanCollide = false
					coroutine.resume(coroutine.create(function()
						print(purchasedItems:FindFirstChild(v.Dependency.Value))
						if purchasedItems:FindFirstChild(v.Dependency.Value) then
							v.Button.Transparency = 0
							v.Button.CanCollide = true
						end
					end))
				end
				
				
				v.Button.Touched:Connect(function(hit)
					local player = game.Players:GetPlayerFromCharacter(hit.Parent)
					if player then
						if values.OwnerValue.Value == player then
							if v.Button.CanCollide == true then
								if player:FindFirstChild("leaderstats").Cash.Value >= v.Price.Value then
									player.leaderstats.Cash.Value -= v.Price.Value
									objects[v.Object.Value].Parent = purchasedItems
									v:Destroy()
								end
							end
						end
					end
				end)
			end
		end)
	end
end

It’s returning NIL on the print.

1 Like

Which print is returning nil? 123123

1 Like