So I made an script but when I first tested it out the two(can be multiple) models we’re overlapping each other which should not happen.
So I changed the script to this;(I’m not sure if this script is overlapping the models too cause I’m getting a error.)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReplicatedStorage2 = game.ReplicatedStorage.Folder1
local Order = ReplicatedStorage:WaitForChild("CreateOrderRequest")
local bf = game.Workspace:WaitForChild("AcceptOrder")
local PassAcceptedOrderData = game.Workspace:WaitForChild("PassAcceptedOrderData")
local char = {
"OldTv";
"Salora58UA330";
}
local Value1 = 15
local Value2 = 120
local function orderRequest(player)
print("ok")
for i, v in pairs(ReplicatedStorage2:GetChildren()) do
if v.Name == "OldTv" then
local Order1 = player.PlayerGui.ComputerMenu.Orders.Background1.Order1
Order1.Visible = false
Order1.Text = ""
Order1.TVSelecter.Text = ""
local CompleteOrder = Instance.new("BoolValue")
CompleteOrder.Parent = ReplicatedStorage2
CompleteOrder.Value = true
local OnlyZone = game.Workspace.StandardBuilding.Storage.Places.OrderValue
local zone = game.Workspace.StandardBuilding.Storage.Places
if CompleteOrder.Value == true and OnlyZone.Value <= 4 then
for i = 1, 4 do
local OrderPlacer = game.Workspace.StandardBuilding.Storage.TruckDoorParts.OrderPlacer
local WhiteBox = OrderPlacer["Place"..i].PackagePlace.SelectionBox
WhiteBox.Visible = true
wait(0.5)
if WhiteBox.Visible == true and OnlyZone.Value <= 6 then
print(OnlyZone.Value)
for spot = 1, 4 do
print(spot)
local Places = game.Workspace.StandardBuilding.Storage.Places
local Spots = Places["Spot"..spot].Part
if Spots then
for z = 1, 4 do
if Places["Spot"..z].Part:FindFirstChild("tvBox") then
local BoxToStorage = Spots:FindFirstChild("tvBox")
BoxToStorage:SetPrimaryPartCFrame(OrderPlacer["Place"..i].PackagePlace.CFrame)
BoxToStorage.Parent = OrderPlacer["Place"..i].PackagePlace
print(spot)
OnlyZone.Value = OnlyZone.Value - 1
end
end
end
end
end
end
game.Workspace.StandardBuilding.Storage.TruckDoorParts.OrderPlacer.Place1.PackagePlace.SelectionBox.Visible = true
wait(5)
else
local StorageTutorialgiver = ReplicatedStorage:WaitForChild("StorageTutorialgiver")
StorageTutorialgiver:FireClient(player)
end
end
end
end
Order.OnServerInvoke = orderRequest
The error is pretty straightforward. There are two options: 1) The model doesn’t exist (so it’s nil), 2) The model doesn’t have a PrimaryPart. Try checking again your script with those 2 possible problems in mind.
So what you’re saying is that there are two models with replicate names in the same table/folder/model/whatever you’re looking at? If so then that’s an issue as :FindFirstChild() doesn’t understand which instance you are referring to.
Can you try removing the third numerical for loop, for z = 1, 4 do, but keep the stuff inside, including the if condition?
You are correctly checking for the existence of an instance before getting it, but you are using the z variable in the condition instead of spot.
-- ...
print(OnlyZone.Value)
for spot = 1, 4 do
print(spot)
local Places = game.Workspace.StandardBuilding.Storage.Places
local Spots = Places["Spot"..spot].Part
if Spots then
local BoxToStorage = Spots:FindFirstChild("tvBox")
if BoxToStorage then
BoxToStorage:SetPrimaryPartCFrame(OrderPlacer["Place"..i].PackagePlace.CFrame)
BoxToStorage.Parent = OrderPlacer["Place"..i].PackagePlace
print(spot)
OnlyZone.Value = OnlyZone.Value - 1
end
end
end
-- ...
The error means that when you do object:SetPrimaryPartCFrame()
object is nil. It has nothing to do with the primary part or anything, but somehow object is nil on this line.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReplicatedStorage2 = game.ReplicatedStorage.Folder1
local Order = ReplicatedStorage:WaitForChild("CreateOrderRequest")
local bf = game.Workspace:WaitForChild("AcceptOrder")
local PassAcceptedOrderData = game.Workspace:WaitForChild("PassAcceptedOrderData")
local char = {
"OldTv";
"Salora58UA330";
}
local Value1 = 15
local Value2 = 120
local function orderRequest(player)
print("ok")
for i, v in pairs(ReplicatedStorage2:GetChildren()) do
if v.Name == "OldTv" then
local Order1 = player.PlayerGui.ComputerMenu.Orders.Background1.Order1
Order1.Visible = false
Order1.Text = ""
Order1.TVSelecter.Text = ""
local CompleteOrder = Instance.new("BoolValue")
CompleteOrder.Parent = ReplicatedStorage2
CompleteOrder.Value = true
local OnlyZone = game.Workspace.StandardBuilding.Storage.Places.OrderValue
local zone = game.Workspace.StandardBuilding.Storage.Places
if CompleteOrder.Value == true and OnlyZone.Value <= 4 then
for i = 1, 4 do
local OrderPlacer = game.Workspace.StandardBuilding.Storage.TruckDoorParts.OrderPlacer
local WhiteBox = OrderPlacer["Place"..i].PackagePlace.SelectionBox
WhiteBox.Visible = true
wait(0.5)
if WhiteBox.Visible == true and OnlyZone.Value <= 6 then
print(OnlyZone.Value)
for spot = 1, 4 do
print(spot)
local Places = game.Workspace.StandardBuilding.Storage.Places
local Spots = Places["Spot"..spot].Part
if Spots then
if Places["Spot"..i].Part then
local NamesData = {"tvBox", "tvBox1"}
for i, v in pairs(Places["Spot"..i].Part:GetChildren()) do
print("poep")
if v.Name == "tvBox" or "tvBox1" then
print("peop")
local BoxToStorage = Spots:FindFirstChild("tvBox" or "tvBox1")
BoxToStorage:SetPrimaryPartCFrame(OrderPlacer["Place"..i].PackagePlace.CFrame)
BoxToStorage.Parent = OrderPlacer["Place"..i].PackagePlace
print(spot)
warn("LOL")
OnlyZone.Value = OnlyZone.Value - 1
end
end
end
end
end
end
end
game.Workspace.StandardBuilding.Storage.TruckDoorParts.OrderPlacer.Place1.PackagePlace.SelectionBox.Visible = true
wait(5)
else
local StorageTutorialgiver = ReplicatedStorage:WaitForChild("StorageTutorialgiver")
StorageTutorialgiver:FireClient(player)
end
end
end
end
Order.OnServerInvoke = orderRequest
This is what is happening and what should happen is that when the second white box line is visible then the second model should be placed at that position.
The model isn’t from a certain folder. There are 6 folders with each a model eventually. So I made an for loop so this would be easier. But when I made those SelectionBoxes the script got changed. So I putted another for loop in it “for * = 1,4” instead of “for * = 1,6”. And when I tried it out it worked. But when I did 2 models in the storage and then pressing the order it gave an error.(same as I showed in one of the replies before) . So yea I don’t really know why it works, but I really do hope this is fixable.
Or do I need to make this script all from scratch again?