Hello.
I am trying to make a Murder Mystery type game instead of spawning with Weapons, they are spawned at different locations and a randomized number is chosen to make it more interesting. Each Murder Item spawns at a part named Murder which has to be pointed out that there is also Neutral and Sheriff Item spawns in the same folder so it has to include that the part must be named “Murder.”
I’m trying to figure out how to make sure no Murderer’s Weapons spawn at the same spot across a total of 6 different spots and I keep getting this error. I am not too experience with scripting to the point where I know how to fix this issue.
Don’t mind that the line 34 says Sheriff instead of Murder Item. Along with all the other spelling mistakes.
TotalItems - Top amount I want spawned.
ChosenItem - Item chosen this game
Code leading up to it:
function BeginGame(PlayerTable)
warn("Randomizing Players | Game Runner")
print(Players)
if #Players < 2 then
warn("Not Enough Players to start a game! | Game Runner")
end
if #Players < 2 then return end
--Randomizing
Events.ScreenFade:FireAllClients(true, true)
local AllMaps = Maps:GetChildren()
local ChosenMap = AllMaps[math.random(1, #AllMaps)]
local LoadedMap = ChosenMap:Clone()
LoadedMap.Parent = workspace.Game
print("Map Choosen | Game Runner")
--Sheriff Items
local SheriffItems = Tools.Sheriff:GetChildren()
local ChosenShItem = SheriffItems[math.random(1, #SheriffItems)]
local SheriffTool = ChosenShItem:Clone()
SheriffTool.Handle.CFrame = LoadedMap:FindFirstChild("ItemSpawns").Sheriff.CFrame
print("Sheriff Item Spawned | Game Runner")
--Murder Items
local MurderItems = Tools.Murder:GetChildren()
local ChosenMRItem = MurderItems[math.random(1, #MurderItems)]
local TotalItems = math.random(2, 6)
local SpawnedMrItems = 0
repeat
local LoadMrItem = ChosenMRItem:Clone()
SpawnedMrItems = SpawnedMrItems + 1
local ItemSpawn = LoadedMap:FindFirstChild("ItemSpawns").Murder[SpawnedMrItems]
if not ItemSpawn then break end
LoadMrItem.Handle.CFrame = ItemSpawn.CFrame
LoadMrItem.Parent = LoadedMap.Items
until SpawnedMrItems == TotalItems or not LoadedMap:FindFirstChild("ItemSpawns").Murder[SpawnedMrItems+1]
print("Murder Items Spawned | Game Runner")