Error with finding parts

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")

In line 40 you are trying to reference a spot that’s named the SpawnedItems number.
I’m not sure if this code works. Also when you post a script on DevForum please copy and paste it here in pre-formatted text instead of screenshotting it cuz it’s kinda hard to see.
Edit: Oh you placed the code lol.

You should instead name the individual murder spots with their own number like for example: “Murder0” so it’s easier for the script to detect it.
I think there’s a different way to check it, but this is what I can figure out.

local ChosenMRItem = MurderItems[math.random(1,#SheriffItems)]
local TotalItems = math.random 2,6
local SpawnedItems = 0
repeat
local LoadMRItem = ChosenMRItem:Clone()
local ItemSpawn = LoadedMap:FindFirstChild("ItemSpawns").Murder["Murder"..SpawnedItems]
if not ItemSpawn then break end
LoadMRItem.Handle.CFrame = ItemSpawn.CFrame
LoadMRItem.Parent = LoadedMap.Items
until SpawnedMrItems == TotalItems or not Loaded:FindFirstChild("ItemSpawns").Murder["Murder"..SpawnedMrItems+1]
print("Murder Items Spawned | Game Runner")
1 Like

Sorry, it takes long to test, but seems like its working rn and just needa figure out why the local multi test doesnt update the part names and the small naming differences

Thanks for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.