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