Paper keeps running into CFrame error

  1. What do i want to achieve?
    I want the Paper to stop running into a CFrame error – ATTENTION: Look in the lua block below, the one in the what is the issue section, i have pinpointed exactly where the error is occuring

  2. What is the issue?


function RunPrinter(Printer)

	if Printer:GetAttribute("PaperFolders") > 9 then return end

	local Paper = game:GetService("ServerStorage"):WaitForChild("TycoonAssets"):WaitForChild("Paper"):Clone()
	Paper.Anchored = true
	Paper.CanCollide = false

	if Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders") + 1) then

		Paper.Parent = Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders") + 1)

	end

	if Printer:GetAttribute("PaperFolders") < 1 then

		local Folder = Instance.new("Folder", Printer:WaitForChild("Papers"))
		Folder.Name = Printer:GetAttribute("PaperFolders") + 1

		Paper.Parent = Folder

		Folder:SetAttribute("MaxPapers", 10)
		Folder:SetAttribute("CurrentPapers", 0)

		Printer:SetAttribute("PaperFolders", Printer:GetAttribute("PaperFolders") + 1)

	end

	local function SetPaper()

		if Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders")):GetAttribute("CurrentPapers") >= Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders")):GetAttribute("MaxPapers") then

			local Folder = Instance.new("Folder", Printer:WaitForChild("Papers"))
			Folder.Name = Printer:GetAttribute("PaperFolders") + 1

			Paper.Parent = Folder

			Folder:SetAttribute("MaxPapers", 10)
			Folder:SetAttribute("CurrentPapers", 0)

			Printer:SetAttribute("PaperFolders", Printer:GetAttribute("PaperFolders") + 1)

			Paper.CFrame = Printer:WaitForChild("StartPaperPositions"):FindFirstChild(Printer:GetAttribute("PaperFolders")).CFrame

			Paper.Name = Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders")):GetAttribute("CurrentPapers") + 1

		else

			Paper.Parent = Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders"))

			for i, v in pairs(Printer:WaitForChild("Papers"):GetChildren()) do

				if v:GetAttribute("CurrentPapers") >= v:GetAttribute("MaxPapers") then

					Paper:Destroy()

				else

					if v:GetAttribute("CurrentPapers") < 1 then

						if not v:GetAttribute("CurrentPapers") then print("NO CURRENTPAPER FOR: ", v.Name) end

						v:SetAttribute("CurrentPapers", 1)

						Paper.CFrame = Printer:WaitForChild("StartPaperPositions"):FindFirstChild(Printer:GetAttribute("PaperFolders")).CFrame

						Paper.Name = v:GetAttribute("CurrentPapers")

					else

						v:SetAttribute("CurrentPapers", v:GetAttribute("CurrentPapers") + 1)

						local CurrentNumber = v:GetAttribute("CurrentPapers") - 1
						
						print("NUMBER:", v:GetAttribute("CurrentPapers") - 1)

						local FoundInstance = v:FindFirstChild(CurrentNumber)
						
						Paper.Name = v:GetAttribute("CurrentPapers")

						print(v:GetAttribute("CurrentPapers"))

						print(typeof(FoundInstance))

						Paper.CFrame = FoundInstance.CFrame + Vector3.new(0, .1, 0) -- The error is here
						
					end

				end

			end

		end

	end

	SetPaper()

end

3 What solutions have i tried so far?
I have looked all over the devforum but cant find an answer

Code:

-- This is an example Lua code block

function RunPrinter(Printer)

	if Printer:GetAttribute("PaperFolders") > 9 then return end

	local Paper = game:GetService("ServerStorage"):WaitForChild("TycoonAssets"):WaitForChild("Paper"):Clone()
	Paper.Anchored = true
	Paper.CanCollide = false

	if Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders") + 1) then

		Paper.Parent = Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders") + 1)

	end

	if Printer:GetAttribute("PaperFolders") < 1 then

		local Folder = Instance.new("Folder", Printer:WaitForChild("Papers"))
		Folder.Name = Printer:GetAttribute("PaperFolders") + 1

		Paper.Parent = Folder

		Folder:SetAttribute("MaxPapers", 10)
		Folder:SetAttribute("CurrentPapers", 0)

		Printer:SetAttribute("PaperFolders", Printer:GetAttribute("PaperFolders") + 1)

	end

	local function SetPaper()

		if Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders")):GetAttribute("CurrentPapers") >= Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders")):GetAttribute("MaxPapers") then

			local Folder = Instance.new("Folder", Printer:WaitForChild("Papers"))
			Folder.Name = Printer:GetAttribute("PaperFolders") + 1

			Paper.Parent = Folder

			Folder:SetAttribute("MaxPapers", 10)
			Folder:SetAttribute("CurrentPapers", 0)

			Printer:SetAttribute("PaperFolders", Printer:GetAttribute("PaperFolders") + 1)

			Paper.CFrame = Printer:WaitForChild("StartPaperPositions"):FindFirstChild(Printer:GetAttribute("PaperFolders")).CFrame

			Paper.Name = Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders")):GetAttribute("CurrentPapers") + 1

		else

			Paper.Parent = Printer:WaitForChild("Papers"):FindFirstChild(Printer:GetAttribute("PaperFolders"))

			for i, v in pairs(Printer:WaitForChild("Papers"):GetChildren()) do

				if v:GetAttribute("CurrentPapers") >= v:GetAttribute("MaxPapers") then

					Paper:Destroy()

				else

					if v:GetAttribute("CurrentPapers") < 1 then

						if not v:GetAttribute("CurrentPapers") then print("NO CURRENTPAPER FOR: ", v.Name) end

						v:SetAttribute("CurrentPapers", 1)

						Paper.CFrame = Printer:WaitForChild("StartPaperPositions"):FindFirstChild(Printer:GetAttribute("PaperFolders")).CFrame

						Paper.Name = v:GetAttribute("CurrentPapers")

					else

						v:SetAttribute("CurrentPapers", v:GetAttribute("CurrentPapers") + 1)

						local CurrentNumber = v:GetAttribute("CurrentPapers") - 1
						
						print("NUMBER:", v:GetAttribute("CurrentPapers") - 1)

						local FoundInstance = v:FindFirstChild(CurrentNumber)
						
						Paper.Name = v:GetAttribute("CurrentPapers")

						print(v:GetAttribute("CurrentPapers"))

						print(typeof(FoundInstance))

						Paper.CFrame = FoundInstance.CFrame + Vector3.new(0, .1, 0)
						
					end

				end

			end

		end

	end

	SetPaper()

end


2 Likes

What do you mean CFrame error? You have to be more specific.

1 Like

You can’t add a Vector3 to a CFrame, do this instead:

Paper.CFrame = FoundInstance.CFrame * CFrame.new(0, .1, 0) -- CFrame creation accepts vector3 values
1 Like

That’s incorrect. You CAN add a Vector3 to a CFrame

local CF = CFrame.new(1, 1, 1) 
print(CF) -- 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1
local CF2 = CF + Vector3.new(1, 5, 9)
print(CF2) -- 2, 6, 10, 1, 0, 0, 0, 1, 0, 0, 0, 1

Multiplying it by a vector achieves the same result with position, but it removes all orientation and sets the data type to Vector3 instead of a CFrame


TomPlays63, I think the likely error is that the FoundInstance thing is nil or is of the wrong type. What is the output of print(typeof(FoundInstance)) on the previous line?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.