Part not creating

I’m making a pathfinding script, and I’m trying to create a goal part if a tile matches a position, but when I add the line to try and duplicate the part, it breaks the script.

Here’s the script:

for i, tile in pairs(tiles:GetChildren()) do
						local primaryPart = playerPokemon.PrimaryPart
						if tile.Position == primaryPart.Position + distanceTable[key] and tile:GetAttribute("occupiedBy") ~= "pokemon" then
							tween(primaryPart, {CFrame = tile.CFrame * CFrame.Angles(0, math.rad(rotationTable[key]), 0)}, 0.25, nil, nil, true, function()
								for i, tileLookAt in pairs(tiles:GetChildren()) do
									if tileLookAt.Position == primaryPart.Position + distanceTable[key] then
										playerPokemon:PivotTo(CFrame.lookAt(primaryPart.Position, tileLookAt.CFrame.Position))
									end
								end
							end)
							primaryPart.CFrame = CFrame.lookAt(primaryPart.Position, tile.CFrame.Position)
							primaryPart:GetPropertyChangedSignal("Position"):Connect(function()
								camera.CFrame = CFrame.new(playerPokemon.PrimaryPart.Position + Vector3.new(0, 20, 10), playerPokemon.PrimaryPart.Position)
							end)
							--[[createObject("Part", {
								Name = "Goal",
								Size = tile.Size,
								Position = tile.Position,
								Parent = workspace,
								CanCollide = false,
								Transparency = 1,
								createObject("IntValue", {
									Name = "G"
								})
							})]]
							if tile:GetAttribute("occupied") and tile:GetAttribute("occupiedBy") ~= "pokemon" then
								playerData.AddItemToBag(tile:GetAttribute("occupiedBy"), tile:GetAttribute("itemAmount"))
								pickUpItem(playerData.PlayerName, tile:GetAttribute("itemAmount"), tile:GetAttribute("occupiedBy"))
								utilities.PlaySound(require(assetsFolder:WaitForChild("Audio")).PickUpItem)
								tile:SetAttribute("itemAmount", nil)
								tile:WaitForChild(tile:GetAttribute("occupiedBy")):Remove()
								tile:SetAttribute("occupiedBy", "pokemon")
							end
						elseif tile.Position == primaryPart.Position + distanceTable[key] and tile:GetAttribute("occupied") and tile:GetAttribute("occupiedBy") == "pokemon" then
							utilities.PlaySound(require(assetsFolder:WaitForChild("Audio")).Boing)
						end

It’s currently commented, but here’s the culprit:

--[[createObject("Part", {
								Name = "Goal",
								Size = tile.Size,
								Position = tile.Position,
								Parent = workspace,
								CanCollide = false,
								Transparency = 1,
								createObject("IntValue", {
									Name = "G"
								})
							})]]

Any help will be appreciated, thanks!

can you post the code to the createObject function

Yup! Here it is:

function Utilities:CreateObject(Settings)
	local object = Instance.new(self)
	task.spawn(function()
		for i, v in pairs(Settings) do
			local success, err = pcall(function()
				if type(v) == "function" then
					object[i]:Connect(v)
				elseif type(i) == "number" then
					v.Parent = object
				else
					object[i] = v
				end
			end)
			if not success then
				warn("Settings Application '"..i.."' to "..self.." failed. "..err)
			end
		end
	end)
	return object
end

It literally works flawlessly with everything else, so this is very bizzare.

youre calling a CreateObject inside of a CreateObject function here

you should close the old one before calling it another time

createObject("Part", {
	Name = "Goal",
	Size = tile.Size,
	Position = tile.Position,
	Parent = workspace,
	CanCollide = false,
	Transparency = 1,
})
createObject("IntValue", {
	Name = "G"
})

I tried separating the functions and unfortunately it did not work. Any other ideas??