I’m trying to make it so whenever a player joins the game a suitcase spawns on the suitcase spawn brick and if there are already more than 1 suitcases, it moves a few studs away from the previous suitcase so they don’t collide.
The issue is that it doesn’t spawn on the suitcase spawn brick but it always spawns in the same place and the suitcases collide.
I’ve tried making it so the suitcases spawn at 0,0,0 instead of the spawn brick but it still didn’t work
Here’s how the suitcase looks in the explorer
And here’s the script
local suitcase = game:GetService("ServerStorage").Suitcase
local suitcaseSpawn = workspace.SuitcaseSpawn
local suitcaseCount = 0
game.Players.PlayerAdded:Connect(function(plr)
local function spawnSuitcase(cframe)
local suitcaseColor = BrickColor.Random()
local suitcaseClone = suitcase:Clone()
suitcaseClone.Parent = workspace
suitcaseClone.CFrame = suitcaseSpawn.CFrame * cframe
suitcaseClone.Main.BrickColor = suitcaseColor
suitcaseClone.Main.SurfaceGui.TextLabel.Text = plr.Name
suitcaseCount = suitcaseCount + 1
end
if suitcaseCount >= 1 then
spawnSuitcase(CFrame.new(0,0,10))
else
spawnSuitcase(CFrame.new(0,0,0))
end
end)
It would be more appropriate that his suitcase was a model, because the models are made to be used in this kind of cases, something like that:
then this should work
local suitcase = game:GetService("ServerStorage").Suitcase
local suitcaseSpawn = workspace.SuitcaseSpawn
local suitcaseCount = 0
local function spawnSuitcase(plr, cframe)
local suitcaseColor = BrickColor.Random()
local suitcaseClone = suitcase:Clone()
suitcaseClone.Parent = workspace
suitcaseClone:SetPrimaryPartCFrame(suitcaseSpawn.CFrame * cframe)
suitcaseClone.Main.BrickColor = suitcaseColor
suitcaseClone.Main.SurfaceGui.TextLabel.Text = plr.Name
suitcaseCount = suitcaseCount + 1
end
game.Players.PlayerAdded:Connect(function(plr)
if suitcaseCount >= 1 then
spawnSuitcase(plr, CFrame.new(0,2,10)) -- that 2 is to avoid overlap with the floor. Depends on the size of your suitcase
else
spawnSuitcase(plr, CFrame.new(0,2,0))
end
end)
in such a case, you must set the PrimaryPart property of the suitcase for this to work properly