Coding a Murder Mystery Game - In-depth Coding Tutorial

Show me the lines where you determine the sheriff in Master and the function. I’m sorry if I’m making you jump around a lot but seeing all of this will help.

2 Likes

Master (put the full part just in case):

local chosenSheriffPlayer = round.ChooseSheriff(innocentPlayers)
	
	for i, v in pairs(innocentPlayers) do
		if v == chosenSheriffPlayer then
			table.remove(innocentPlayers,i)
			table.insert(sheriff, i)
		end
	end
	wait(2)
	
	round.InsertTag(innocentPlayers, "Innocent")
	round.InsertTag({chosenSheriffPlayer}, "Sheriff")
	round.InsertTag({chosenMurdererPlayer}, "Murderer")
	
	if clonedMap:FindFirstChild("PlayerSpawns") then
		round.TeleportPlayers(innocentPlayers, clonedMap.PlayerSpawns:GetChildren())
		round.TeleportSheriff(chosenSheriffPlayer, clonedMap.PlayerSpawns:GetChildren())
		round.TeleportMurderer(chosenMurdererPlayer, clonedMap.PlayerSpawns:GetChildren())
	else
		warn("Fatal Error: no PlayerSpawns Folder")
	end
	
	round.StartRound(600, chosenMurdererPlayer, clonedMap)
	
	clonedMap:Destroy()
	
	round.RemoveTags()
	
	wait(2)
end

function (the one in the module?):

function module.ChooseSheriff(players)
	local RandomObj = Random.new()

	local chosenSheriff = players[RandomObj:NextInteger(1, #players)]

	return chosenSheriff
end

Upon attempting to join the “Murder Mystery - Tutorial” place I get kicked because “Testing in session!” but there are no people playing and I was on a brand new server every time I got kicked. I assume this means the place is subject to testing for a while more before it’s open to the public?

If you’re interested to see how a final product would like, then here is a game I made using 50% of his system.
https://web.roblox.com/games/6447977074/Massacre-Mystery-BETA

1 Like

So sorry for the inconvenience, I’ve allowed entry once again. Thank you!

Hi friend. I am starting with coding and stuff. This thing you made is awesome.
I have a question… maybe silly question…
here:

local status = game.ReplicatedStorage.Values:WaitForChild("status")
function module.Intermission(length)
	for i = length, 0, -1 do
		status.Value = "Next round in "..i.." seconds"
		wait(1)
	end
end

You made a function in the module script. Why did you call it module.Intermission instead of only Intermission? Is it mandatory the dot?

Then in the master you called it as round.Intermission.. why? Why not calling it using the module.Intermission name? I am confused in this. hope you can help me … :wink:

local Status = game.ReplicatedStorage.Values:WaitForChild("status")
local round = require(script.Round)

while wait() do
	repeat
		local availablePlayers = {}

		for i, plr in pairs(game.Players:GetPlayers()) do
			table.insert(availablePlayers, plr)
		end
		Status.Value = "In order for the round to begin, there must be at least 2 players in the server."
		wait(2)
	until #availablePlayers >= 2
	
	round.Intermission(5)

end

thanks for tutorial!

Hi! No worries, I’m happy to help! we do module.Intermission because when we call the round module, we want that specific function. If we did just Intermission() that function is local to the module, can’t be called anywhere else.

1 Like

thanks for that.
another thing related…


why the module appears with the blue line… and whenhit play… showed me that error … attempt to index nil with “intermission”? SOrry… maybe I made an error but I can see where… :frowning:

Is that script in a module script?

Hi,
Yeah… it is (I guess). It is the one provided with the template. It is called round. image

Create a new one, copy and paste the code you’ve typed into that new one. KEEP THE local module = {} and return module

2 Likes

That worked! I didnt have the local module nor the return :open_mouth: Maybe I deleted
Thanks a lot!
I will continue jeje

1 Like

Hey im sorry but im new in scripting where would i need to put this last part coding?
Because its all working until im doing the part to have custom characters.

Put that into the ChooseMurderer function.

Do i need to replace that over here?

Im really sorry if im wrong but after i can manage to let your script work i would like to learn about scripting then im not that noob right now :rofl:

No no you’re perfectly fine, very typical to have these questions!! Yes, replace lines 16-22 with that function you’ve created (or you could just replace the stuff inside your function with the old function).

Ok thank you :slight_smile: Also is it normal when testing the game in roblox studio im not getting a custom character and when killing the last remaining player the round doesn’t end?

Did you not code in calling the function for dressing the player? Also, you may have not completed the StartRound() function. Please check to see if your code is aligned with mine.

At this point i don’t really know what im doing wrong so i replaced all the code again its all working just with the same issue’s and when im trying to add the code for the custom characters all the scripts seems to stop working.

1 Like

But i think i will stop from this point and try to understand more about scripting. Your Murder Mystery also seems really good so when im far enough i can use your amazing work!