ReplicatedStorage.Module3D:107: attempt to perform arithmetic (mul) on number and nil - Client - Module3D:107

Hello! So I tried polarisprog’s tutorial (https://www.youtube.com/watch?v=3jJRXX-KAaU) and ended up getting this error:
ReplicatedStorage.Module3D:107: attempt to perform arithmetic (mul) on number and nil - Client - Module3D:107.

This is the code that seems to have the error

--This is a local script located in StarterPlayerScripts
local runService = game:GetService("RunService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local tweenService = game:GetService("TweenService")

local eggs = workspace:WaitForChild("MainFolder_Workspace"):WaitForChild("Eggs")
local remotes = replicatedStorage:WaitForChild("Remotes")
local pets = replicatedStorage:WaitForChild("Pets")

local player = players.LocalPlayer
local eggSystemSS = player:WaitForChild("PlayerGui"):WaitForChild("EggSystem")
local eggViewport = eggSystemSS:WaitForChild("EggViewport")

local mainSS = player:WaitForChild("PlayerGui"):WaitForChild("MainSS")
local inventory = mainSS:WaitForChild("PetInventory")
local scrollingFrame = inventory:WaitForChild("ScrollingFrame")
local template = scrollingFrame:WaitForChild("Template")

local module3D = require(replicatedStorage:WaitForChild("Module3D"))

local function onTemplateClick(clickedTemplate)
	if clickedTemplate.Equipped.Value == false then
		for _, v in pairs(scrollingFrame:GetChildren()) do
			if v:IsA("GuiButton") then
				v.Equipped.Value = false
				v.BackgroundColor3 = Color3.fromRGB(152,152,152)
			end
		end
		clickedTemplate.Equipped.Value = true
		clickedTemplate.BackgroundColor3 = Color3.fromRGB(96,235,96)
		remotes.UnequipPets:FireServer()
		remotes.EquipPet:FireServer(clickedTemplate.Name)
	else
		for _, v in pairs(scrollingFrame:GetChildren()) do
			if v:IsA("GuiButton") then
				v.Equipped.Value = false
				v.BackgroundColor3 = Color3.fromRGB(152,152,152)
			end
		end
		remotes.UnequipPets:FireServer()
	end
end

local function createTemplate(petName)
	local newTemplate = template:Clone()
	newTemplate.Name = petName
	newTemplate.Visible = true
	newTemplate.Parent = scrollingFrame
	
	local petModel3D = module3D:Attach3D(newTemplate:WaitForChild("Viewport"), pets:FindFirstChild(petName):clone())
	petModel3D.SetDepthMultiplier(2)
	petModel3D.Camera.FieldOfView = 5
	petModel3D.Visible = true
	
	runService.RenderStepped:Connect(function()
		petModel3D:SetCFrame(CFrame.Angles(0, tick() % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
	end)
	
	newTemplate.MouseButton1Click:Connect(function()
		onTemplateClick(newTemplate)
	end)
end

local function hatchEgg(eggName, chosenPet)
	for _, v in pairs(player.PlayerGui:GetChildren()) do
		if v:IsA("ScreenGui") and v ~= eggSystemSS then
			v.Enabled = false
		end
	end
	eggSystemSS.Enabled = true
	for _, v in pairs(eggViewport:GetChildren()) do
		if v:IsA("Camera") or v:IsA("BasePart") or v:IsA("Model") then
			v:Destroy()
		end
	end
	eggViewport.Size = UDim2.fromScale(0, 0)
	local eggMesh = eggs:FindFirstChild(eggName):Clone()
	eggMesh.Parent = eggViewport
	eggMesh.CFrame = CFrame.new(0, 0, 0)
	local camera = Instance.new("Camera")
	camera.Parent = eggViewport
	camera.CFrame = CFrame.new(0, 0, 4)
	eggViewport.CurrentCamera = camera
	tweenService:Create(eggViewport, TweenInfo.new(0.7), {Size = UDim2.new(0.227, 0,0.403, 0)}):Play()
	task.wait(0.7)
	for i = 1, 4 do
		tweenService:Create(eggViewport, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = 20}):Play()
		task.wait(0.3)
		tweenService:Create(eggViewport, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = -20}):Play()
		task.wait(0.3)
	end
	tweenService:Create(eggViewport, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = 0}):Play()
	task.wait(0.3)
	tweenService:Create(eggViewport, TweenInfo.new(0.7), {Size = UDim2.fromScale(0,0)}):Play()
	task.wait(0.3)
	for _, v in pairs(eggViewport:GetChildren()) do
		if v:IsA("Camera") or v:IsA("BasePart") or v:IsA("Model") then
			v:Destroy()
		end
	end
	local petModel = pets:FindFirstChild(chosenPet.petName):Clone()
	petModel:PivotTo(CFrame.new(0, 0, 0))
	petModel.Parent = eggViewport
	local cameraPet = Instance.new("Camera")
	cameraPet.Parent = eggViewport
	cameraPet.CFrame = CFrame.new(0, 0, -3.3) * CFrame.Angles(0, math.rad(180), 0)
	eggViewport.CurrentCamera = cameraPet
	tweenService:Create(eggViewport, TweenInfo.new(0.7), {Size = UDim2.new(0.227, 0,0.403, 0)}):Play()
	eggViewport.NameLabel.Text = chosenPet.petName
	eggViewport.NameLabel.Visible = true
	eggViewport.RarityLabel.Text = chosenPet.Rarity
	eggViewport.RarityLabel.Visible = true
	task.wait(1.5)
	tweenService:Create(eggViewport, TweenInfo.new(0.3), {Size = UDim2.fromScale(0,0)}):Play()
	task.wait(0.3)
	eggViewport.NameLabel.Visible = false
	eggViewport.RarityLabel.Visible = false
	createTemplate(chosenPet.petName)
	for _, v in pairs(player:WaitForChild("PlayerGui"):GetChildren()) do
		if v:IsA("ScreenGui") and v ~= eggSystemSS then
			v.Enabled = true
		end
	end
end

remotes:WaitForChild("HatchEgg").OnClientEvent:Connect(hatchEgg)

I checked all of the parts of the tutorial, and it seemed exactly the same. I tried using prints to check for the error, and I eventually figured that PetModel3D is nil, but I don’t know how to fix it. Can anyone help?

1 Like

the code you sent looks fine, your compiled version is probably running some kind of different code; if you have team create/code drafting on then make sure that the code you sent is also the committed version

you can download a local copy of the game, re-insert the code, and then test it to see if it is a draft issue, in which case you’re best off just re-opening the game and looking into how committing script changes work

if that’s not the case, then you either have given us incorrect information or studio is reaaally buggin out

1 Like

I can give access to the game if needed using collaborate, tried saving the entire game as a local copy and it did nothing
Here are the images for reference
image
image

1 Like

test.rbxl (274.0 KB)

1 Like

Nevermind, I found a solution. It turns out there was a period here: petModel3D.SetDepthMultiplier(2) (It was supposed to be a colon).

1 Like

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