YandereDev Syndrome

Ok so, as said in the title, I got a bit of a YandereDev Syndrome here by using lots of elseif for a random number.
The random number chooses a random spawn point on each respective side. (See Video)

How can I shorten this horrendous “code”?

You can make a folder in workspace named “RandomSpawns” and use its children to choose a spawn location

local spawnsList = workspace.RandomSpawns:GetChildren()
local randomSpawn = spawnsList[math.random(#spawnsList)]
Clone.Parent = workspace
Clone:PivotTo(randomSpawn:GetPivot())

This’ll also stop the “magic numbers” floating around which makes it way easier to read and you don’t have to manually edit it with every new spawn you add

2 Likes

Just change it to one check like this

Clone.Parent = workspace
Clone:PivotTo(workspace["Part"..Number]:GetPivot())
print(RandomSpawn)