I am trying to make something where packages drop from random spawners.
I am going well with the code but I am having a slight issue which I can’t seem to highlight.
It keeps giving me: CFrame is not a valid member of Tool “Workspace.RedBox” But the thing is that the box spawns and drops down to the right spawner but then no boxes come after it.
Here is my code:
local MailJob = game.Workspace.Jobs.MailJob
local Spawns = MailJob.Spawner
local Packages = game:GetService("ServerStorage"):WaitForChild("Packages")
local Spawn1 = Spawns.One
local Spawn2 = Spawns.Two
local Spawn3 = Spawns.Three
local RedBox = Packages.RedBox
local BlueBox = Packages.BlueBox
local Envelope = Packages.Envelope
while wait(1) do
local randomSpawn = math.random(1,3)
local randomPackage = math.random(1,3)
-- 1 = RedBox
-- 2 = BlueBox
-- 3 = Envelope
if randomSpawn == 1 then
--Spawn 1
if randomPackage == 1 then
local SpawnRed = RedBox:Clone()
SpawnRed.Parent = game.Workspace
SpawnRed.CFrame = Spawn1.CFrame
elseif randomPackage == 2 then
local SpawnBlue = BlueBox:Clone()
SpawnBlue.Parent = game.Workspace
SpawnBlue.CFrame = Spawn1.CFrame
elseif randomPackage == 3 then
local SpawnEnvelope = Envelope:Clone()
SpawnEnvelope.Parent = game.Workspace
SpawnEnvelope.CFrame = Spawn1.CFrame
end
--Spawn 1
elseif randomSpawn == 2 then
--Spawn 2
if randomPackage == 1 then
local SpawnRed = RedBox:Clone()
SpawnRed.Parent = game.Workspace
SpawnRed.CFrame = Spawn2.CFrame
elseif randomPackage == 2 then
local SpawnBlue = BlueBox:Clone()
SpawnBlue.Parent = game.Workspace
SpawnBlue.CFrame = Spawn2.CFrame
elseif randomPackage == 3 then
local SpawnEnvelope = Envelope:Clone()
SpawnEnvelope.Parent = game.Workspace
SpawnEnvelope.CFrame = Spawn2.CFrame
end
--Spawn 2
elseif randomSpawn == 3 then
--Spawn 3
if randomPackage == 1 then
local SpawnRed = RedBox:Clone()
SpawnRed.Parent = game.Workspace
SpawnRed.CFrame = Spawn3.CFrame
elseif randomPackage == 2 then
local SpawnBlue = BlueBox:Clone()
SpawnBlue.Parent = game.Workspace
SpawnBlue.CFrame = Spawn3.CFrame
elseif randomPackage == 3 then
local SpawnEnvelope = Envelope:Clone()
SpawnEnvelope.Parent = game.Workspace
SpawnEnvelope.CFrame = Spawn3.CFrame
end
--Spawn 3
end
end
2 Likes
I’m going to assume that RedBox is a Model, Models don’t have CFrames
You’ll have to use Model:SetPrimaryPartCFrame()
Also make sure you set a PrimaryPart to the Model
EDIT: nvm I see you said it’s a Tool, tools also don’t have a CFrame property
1 Like
Tools don’t have a CFrame
property, you’ll have to reference the Tool’s Handle instead since it’s a BasePart
local MailJob = game.Workspace.Jobs.MailJob
local Spawns = MailJob.Spawner
local Packages = game:GetService("ServerStorage"):WaitForChild("Packages")
local Spawn1 = Spawns.One
local Spawn2 = Spawns.Two
local Spawn3 = Spawns.Three
local RedBox = Packages.RedBox
local BlueBox = Packages.BlueBox
local Envelope = Packages.Envelope
while wait(1) do
local randomSpawn = math.random(1,3)
local randomPackage = math.random(1,3)
-- 1 = RedBox
-- 2 = BlueBox
-- 3 = Envelope
if randomSpawn == 1 then
--Spawn 1
if randomPackage == 1 then
local SpawnRed = RedBox:Clone()
SpawnRed.Parent = game.Workspace
SpawnRed.Handle.CFrame = Spawn1.CFrame
elseif randomPackage == 2 then
local SpawnBlue = BlueBox:Clone()
SpawnBlue.Parent = game.Workspace
SpawnBlue.Handle.CFrame = Spawn1.CFrame
elseif randomPackage == 3 then
local SpawnEnvelope = Envelope:Clone()
SpawnEnvelope.Parent = game.Workspace
SpawnEnvelope.Handle.CFrame = Spawn1.CFrame
end
--Spawn 1
elseif randomSpawn == 2 then
--Spawn 2
if randomPackage == 1 then
local SpawnRed = RedBox:Clone()
SpawnRed.Parent = game.Workspace
SpawnRed.Handle.CFrame = Spawn2.CFrame
elseif randomPackage == 2 then
local SpawnBlue = BlueBox:Clone()
SpawnBlue.Parent = game.Workspace
SpawnBlue.Handle.CFrame = Spawn2.CFrame
elseif randomPackage == 3 then
local SpawnEnvelope = Envelope:Clone()
SpawnEnvelope.Parent = game.Workspace
SpawnEnvelope.Handle.CFrame = Spawn2.CFrame
end
--Spawn 2
elseif randomSpawn == 3 then
--Spawn 3
if randomPackage == 1 then
local SpawnRed = RedBox:Clone()
SpawnRed.Parent = game.Workspace
SpawnRed.Handle.CFrame = Spawn3.CFrame
elseif randomPackage == 2 then
local SpawnBlue = BlueBox:Clone()
SpawnBlue.Parent = game.Workspace
SpawnBlue.Handle.CFrame = Spawn3.CFrame
elseif randomPackage == 3 then
local SpawnEnvelope = Envelope:Clone()
SpawnEnvelope.Parent = game.Workspace
SpawnEnvelope.Handle.CFrame = Spawn3.CFrame
end
--Spawn 3
end
end
3 Likes
Thank you very much and I also have one more question, how would I possible make it so that when I touch the tool, it does not put it in my inventory automatically? I think it might be a property I just can’t circle which one.
I believe you could just replace the Tool
with the actual BasePart itself, and depending on when you want it Equipped you can use a ProximityPrompt
parented inside the Part which is basically an interaction object, and upon activation you can give the Tool to the player that way
(Another way is just renaming the Handle Part to something else I suppose)
1 Like