I’m making a game where it spawns random trinket around the map. I’ve created a script that have a 1/5 chance to spawn a random item every 10 seconds, but it requires me to put the script on every spawn location. Is there a more better and efficient way to make this?
Script:
task.wait(5)
local chance = math.random(1,5)
if chance == 1 then
print("item spawn chance")
local trinket = math.random(1, 5)
if trinket == 1 then
local item = game.ServerStorage.TrinketsClicker.Bracelet:Clone()
item.Parent = workspace.SpawnedTrinkets
item.Position = script.Parent.Position
elseif trinket == 2 then
local item = game.ServerStorage.TrinketsClicker["Diamond Ring"]:Clone()
item.Parent = workspace.SpawnedTrinkets
item.Position = script.Parent.Position
elseif trinket == 3 then
local item = game.ServerStorage.TrinketsClicker["Gold Goblet"]:Clone()
item.Parent = workspace.SpawnedTrinkets
item.Position = script.Parent.Position
elseif trinket == 4 then
local item = game.ServerStorage.TrinketsClicker["Golden Necklace"]:Clone()
item.Parent = workspace.SpawnedTrinkets
item.Position = script.Parent.Position
elseif trinket == 5 then
local item = game.ServerStorage.TrinketsClicker["Metal Plate"]:Clone()
item.Parent = workspace.SpawnedTrinkets
item.Position = script.Parent.Position
end
else
print("didnt spawn")
end
end ```