I’ve been making some admin commands and recently made it so I can spawn in props with a command.
While it functions normally, when I try to spawn in a shipping container prop, the game will crash upon trying to set it’s parent to game.Workspace
.
Below is a video demonstrating what happens:
[Link to video if embed fails]
Here is the code for spawning a prop:
SpawnObject = function(player, data)
--Check
local passed = Functions.CheckForPermissions(player, 1)
if passed == false then end
--End Check
--Parameters
local object = nil
local group = nil
local position = nil
if data.InputMethod == "Command" then
for i, item in pairs(data) do
if string.lower(item) == "in" then
group = data[i + 1]
elseif string.lower(item) == "at" then
local target = Functions.FindTarget(data[i + 1], true)
if target ~= nil and target.Character ~= nil and target.Character.PrimaryPart ~= nil then
position = target.Character.PrimaryPart.Position
end
elseif i ~= "InputMethod" and (i == 1 or (string.lower(data[i - 1]) ~= "in" and string.lower(data[i - 1]) ~= "at")) then
if object == nil then
object = item
else
object = object.." "..item
end
end
end
end
--Code
if object ~= nil and ((group ~= nil and Resources.Objects:FindFirstChild(group) and Resources.Objects[group]:FindFirstChild(object)) or Resources.Objects:FindFirstChild(object, true)) then
local clone = nil
print("cloning")
task.wait(1)
if group ~= nil then
clone = Resources.Objects[group][object]:Clone()
else
clone = Resources.Objects:FindFirstChild(object, true):Clone()
end
print("cloned")
task.wait(1)
print(clone, clone.Parent)
task.wait(1)
print("parenting to workspace") --This is where the game crashes
clone.Parent = game.Workspace
print("parented to workspace")
task.wait(1)
print("setting position")
if clone:IsA("Model") then
if position ~= nil then
clone:SetPrimaryPartCFrame(CFrame.new(position))
else
clone:SetPrimaryPartCFrame(CFrame.new((player.Character.PrimaryPart.CFrame.LookVector * clone:GetExtentsSize().X/2) + player.Character.PrimaryPart.Position))
end
else
if position ~= nil then
clone.CFrame = CFrame.new(position)
else
clone.CFrame = CFrame.new((player.Character.PrimaryPart.CFrame.LookVector * clone:GetExtentsSize().X/2) + player.Character.PrimaryPart.Position)
end
end
end
end,
And here is the Shipping Container Object:
Any help would be appreciated. Thanks!