The Model Goes Nil On Server

Im Creating A Building System like the game oga boga and when i get the CFrame and a String says: ReplicatedStorage.Modules.Crafting:26: attempt to index nil with 'Clone' - Server - Crafting:26

here’s the code:

Local(gui)

Crafting.MainFrame.ScrollingFrame.ChildAdded:Connect(function(Slot)
	warn("Created:", Slot.Name, "Recepie")
	if Slot:IsA("TextButton") then
		Slot.MouseButton1Click:Connect(function()
			if ReplicatedStorage.Assets.Crafting[Slot.Name].Model.Value.Parent.Name == "Building" then
				local CanCraft = CheckCrafting(Slot.Name)
				if CanCraft == true then
					ReplicatedStorage.Remotes.CraftObject:InvokeServer(Slot.Name, true)
					local Model:Model = ReplicatedStorage.Assets.Crafting[Slot.Name].Model.Value:Clone()
					Model.Parent = workspace
					local Button = Info.PlaceBuilding:Clone()
					Button.Parent = Info
					Button.Visible = true
					for i, part in pairs(Model:GetDescendants()) do
						if part:IsA("BasePart") then
							if part.Name == "Primary" then
								part.Transparency = 1
								else
								part.BrickColor = BrickColor.new("Lime green")
								part.Material = Enum.Material.ForceField
							end
						end
					end

					RunService.RenderStepped:Connect(function()
						Model:PivotTo(player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-15))
						Button.MouseButton1Click:Connect(function()
							Button:Destroy()
							ReplicatedStorage.Remotes.PlaceBuilding:InvokeServer(Model.PrimaryPart.CFrame, Model.Name) --the Call To Server
							wait()
							Model:Destroy()
						end)
						wait()
					end)
				end
			else
				local CanCraft = CheckCrafting(Slot.Name)
				if CanCraft == true then
					ReplicatedStorage.Remotes.CraftObject:InvokeServer(Slot.Name, false)
				end
			end
		end)
	end

Module(server)

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Building = ReplicatedStorage.Assets.Building

local module = {}

function module.CraftObject(Player, ObjName, IsBuilding)
	if IsBuilding == false then
		local Amount:number = ReplicatedStorage.Assets.Crafting[ObjName].Amount.Value
		Player.Materials[ObjName].Value += Amount

		local Materials = ReplicatedStorage.Assets.Crafting[ObjName].Materials:GetChildren()
		for i, Material in pairs(Materials) do
			Player.Materials[Material.Name].Value -= Material.Value
		end
	elseif IsBuilding == true then
		local Materials = ReplicatedStorage.Assets.Crafting[ObjName].Materials:GetChildren()
		for i, Material in pairs(Materials) do
			Player.Materials[Material.Name].Value -= Material.Value
		end
	end
end

function module.PlaceBuilding(PrimaryPartCFrame, ModelName)
	local Build = Building:FindFirstChild(ModelName):Clone() -- the error starts here
	
	Build:PivotTo(PrimaryPartCFrame)
	Build.Parent = workspace
	Build.PrimaryPart:Destroy()
end

return module

please help me i tried for 30 minuites straight

It can’t find the building piece inside of the Buildings folder

it’s called: Cabin here’s a screenshot:
image

Where is this even going by the way?

Wait my bad i mean this

first main:

-- CraftingRemotes

remotes.CraftObject.OnServerInvoke = CraftingModule.CraftObject

remotes.PlaceBuilding.OnServerInvoke = CraftingModule.PlaceBuilding

then on the Module:

function module.PlaceBuilding(PrimaryPartCFrame, ModelName)
	local Build = Building:FindFirstChild(ModelName):Clone() -- the error starts here
	
	Build:PivotTo(PrimaryPartCFrame)
	Build.Parent = workspace
	Build.PrimaryPart:Destroy()
end

return module

Yeah but shouldnt you have a function that handles when the server was invoked?

and it works because up the main there is more things going in another module for the inventory

But where are you actually handling the invokation on the server side for placing a building?

first it goes from CraftingHandler(localSide) to main(serverScriptService) then to the Module(also Server sided)

Okay caan you show the invokation function you have on the server side before it goes to the module?

this one is the Call for sever to module

Oh my bad I See okay so trying doing this

function module.PlaceBuilding(player, PrimaryPartCFrame, ModelName)
	local Build = Building:FindFirstChild(ModelName):Clone() -- the error starts here
	
	Build:PivotTo(PrimaryPartCFrame)
	Build.Parent = workspace
	Build.PrimaryPart:Destroy()
end

return module
1 Like

oh im dumb . _ . thanks :sweat_smile:

1 Like

dude it be like that sometimes trust me

1 Like

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