I dont know how to fix this, what do i do?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A game called FRAUD, about betrayal.
  2. What is the issue? Include screenshots / videos if possible!
    The main script breaks on the survivors’ turn, causing the turn to never end, even if a player dies.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Adding break statements to the loop, etc.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A cool, unusual game of betrayal and pvp.
  2. What is the issue? Include screenshots / videos if possible!
    it… breaks.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    none.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

my code:

local plrs = 0
local delay3 = false
local delay4 = false
local delay = false
local delay5 = false
local timer = 60
local Skip = false
local Headband = Instance.new("Hint")
local Clues = {"The monster must be near someone to kill them.", "The monster can only kill before voting.", "The monster looks like one of you.", "The monster cannot vote."}
game["Run Service"].Heartbeat:Connect(function()
	if workspace.MonsterTurn.Value == true then
		if delay5 == false then
			delay5 = true
			wait(1)
			timer -= 1
			print(timer)
			if timer < 0 then
				Headband.Text = "The monster killed nobody within 1 minute. Skipping."
				wait(5)
				workspace.SkipTurn.Value = true
			end
			delay5 = false
		end
	else
		timer = 60
	end
	if delay == false then
		delay = true
		Headband.Parent = workspace
		workspace.GameOver.Value = false
		for i = 1, 30 do
			Headband.Text = "Round starting in " .. 30 - i .. " seconds."
			wait(1)
		end
		if #game.Players:GetPlayers() < 4 then
			Headband.Text = "Not Enough Players."
			wait(3)
		else
			Headband.Text = "You have time to split up. Do so."
			for i, plr in pairs(game.Players:GetPlayers()) do
				if plr.Character then
					plr.Character:PivotTo(workspace.Spawns:GetChildren()[math.random(1, #workspace.Spawns:GetChildren())].CFrame)
					plr:AddTag("Ingame")
				end
			end
			
			workspace.Fraud.Value = game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())]
			while workspace.GameOver.Value == false do
				wait()
				if delay4 == false then
					delay4 = true
					Headband.Text = "The monster is attacking."
					workspace.MonsterTurn.Value = true
					workspace.LastVoted.Value = game
					while workspace.GameOver.Value ~= true and Skip ~= true do
						wait()
						if workspace.SkipTurn.Value == true then
							Skip = true
							print("Skip!")
						end
					end
					Skip = false
					workspace.SkipTurn.Value = false
					Headband.Text = "Figure out and kill the monster. It is everybody (not the monster)'s turn. clue: " .. Clues[math.random(1, #Clues)]
					workspace.MonsterTurn.Value = false
					workspace.LastVoted.Value = game
					while workspace.GameOver.Value ~= true and Skip ~= true do
						wait()
						if workspace.SkipTurn.Value == true then
							Skip = true
							print("Skip!")
						end
					end
					Skip = false
					workspace.SkipTurn.Value = false
					if workspace.GameOver.Value == true then
						if workspace.Lost.Value == true then
							Headband.Text = "The monster won. The monster was: " .. workspace.Fraud.Value.DisplayName
							workspace.Lose:Play()
						else
							Headband.Text = "The survivors win. The monster was: " .. workspace.Fraud.Value.DisplayName
							workspace.Win:Play()
						end
						for i, plr in pairs(game.Players:GetPlayers()) do
							plr:LoadCharacter()
						end
						wait(5)
						delay = false
						delay4 = false
					end
				end
			end
			end
	end
end)

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		local Prompt = Instance.new("ProximityPrompt")
		local Attach = Instance.new("Attachment")
		Attach.Parent = Char.Head
		Attach.Position = Vector3.new(0, 3, 0)
		Prompt.Parent = Attach
		Prompt.RequiresLineOfSight = false
		Prompt.HoldDuration = 1
		Prompt.MaxActivationDistance = 7
		Prompt.ActionText = "Vote/Kill"
		Prompt.ObjectText = Player.DisplayName
		Prompt.Triggered:Connect(function(Plr)
			if ((Plr ~= Player and workspace.Fraud.Value ~= Plr and workspace.MonsterTurn.Value == false) or (workspace.Fraud.Value == Plr and workspace.MonsterTurn.Value == true)) and Player:HasTag("Ingame") and Plr:HasTag("Ingame") then
				Char:BreakJoints()
				if Player:HasTag("Ingame") then
					Player:RemoveTag("Ingame")
					workspace.LastVoted.Value = Player
					workspace.SkipTurn.Value = true
					for i, bp in pairs(Char:GetChildren()) do
						if bp:IsA("BasePart") then
							bp.Color = Color3.fromRGB(255, 0, 4)
						end
					end
					workspace["Scare Stings 11"]:Play()
				end
			end
		end)
	end)
end)
local Delay2 = false
workspace.LastVoted.Changed:Connect(function(E)
	workspace.LastVoted.Value = nil
	if Delay2 == false then
		Delay2 = true
		plrs = 0
		workspace.Lost.Value = true
		for i, plr in pairs(game.Players:GetPlayers()) do
			if plr:HasTag("Ingame") then
				plrs += 1
			end
			if plr == workspace.Fraud.Value and not plr:HasTag("Ingame") then
				workspace.Lost.Value = false
				workspace.GameOver.Value = true
			end
		end
		if plrs < 3 then
			workspace.GameOver.Value = true
		end
		Delay2 = false
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Have you checked the console? (type /console in chat in the client or use output in the studio.)

Check for errors, a thrown error halts the script.

yeah, i did, but there were no errors.

The reason why no one is answering is because it’s extremely hard to debug this code, it’s very messy. Can you elaborate on how the code is “breaking”? What is it supposed to do?

Also, why did you make two posts?

1 Like

i made two posts because i didnt know what to do, and i was in a rush when i made this.
also its supposed to script the entire game.
look for while loops, they are the problem

Putting everything in one script isn’t recommended, I’d recommended splitting it up, especially the parts that do totally different things, and aren’t related. It will make it easier to debug.

i enjoy having 1 compact script.
im me.

It uses less scripts but it can easily make your code spaghetti

spaghetti code works, but it’s bad, because if you want to change anything / you find a bug it takes a lot more effort then it should to change / fix it.

Always use modules if you need to reuse code.

If a task can be done by other scripts, then do so.

Having one script do all the work could come back to bite you (I know from experience)

hey, idk how to use modulescripts

1 Like

You can try reading the documentation

https://create.roblox.com/docs/reference/engine/classes/ModuleScript

(oopsies wrong link)

I agree. You won’t become a better scripter if you don’t, at this level you won’t be able to make anything note-worthy.

2 Likes

Hello! I believe I may have found your problem.

It took a few glances, so I may have missed something, but it seems as though once a player is voted out and killed, two values are changed immediately: LastVoted.Value and SkipTurn.Value. Changing the value of LastVoted invokes the event on the line containing workspace.LastVoted.Changed:Connect(function(E).

I believe that after you update the value of SkipTurn, which you’re using to check whether or not to break the loop, THAT code runs faster than the code in the LastVoted.Changed event, which causes the loop to break while GameOver.Value is still false, and thus doesn’t run any of the code in the if statement shortly after your loop breaks.

A potential solution would be to add another loop shortly before that if statement to wait until the LastVoted.Changed event to finish processing. Consider adding something like this on the line before the check for GameOver.Value.

repeat
  task.wait(0.1)
until not Delay2

Since your event sets Delay2 to true as long as it runs, we can use that to wait until we know it’s finished. Hopefully, this will prevent us from running the check before the event finishes, and this issue in particular should be resolved.

didnt work
can you code it in for me please?
i tried implementing it, but it failed
same problem
its buggier now

Sure,

Updating your script to the following should hopefully reflect the behavior we want.

local delay5 = false
local timer = 60
local Skip = false
local Headband = Instance.new("Hint")
local Clues = {"The monster must be near someone to kill them.", "The monster can only kill before voting.", "The monster looks like one of you.", "The monster cannot vote."}
game["Run Service"].Heartbeat:Connect(function()
	if workspace.MonsterTurn.Value == true then
		if delay5 == false then
			delay5 = true
			wait(1)
			timer -= 1
			print(timer)
			if timer < 0 then
				Headband.Text = "The monster killed nobody within 1 minute. Skipping."
				wait(5)
				workspace.SkipTurn.Value = true
			end
			delay5 = false
		end
	else
		timer = 60
	end
	if delay == false then
		delay = true
		Headband.Parent = workspace
		workspace.GameOver.Value = false
		for i = 1, 30 do
			Headband.Text = "Round starting in " .. 30 - i .. " seconds."
			wait(1)
		end
		if #game.Players:GetPlayers() < 4 then
			Headband.Text = "Not Enough Players."
			wait(3)
		else
			Headband.Text = "You have time to split up. Do so."
			for i, plr in pairs(game.Players:GetPlayers()) do
				if plr.Character then
					plr.Character:PivotTo(workspace.Spawns:GetChildren()[math.random(1, #workspace.Spawns:GetChildren())].CFrame)
					plr:AddTag("Ingame")
				end
			end
			
			workspace.Fraud.Value = game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())]
			while workspace.GameOver.Value == false do
				wait()
				if delay4 == false then
					delay4 = true
					Headband.Text = "The monster is attacking."
					workspace.MonsterTurn.Value = true
					workspace.LastVoted.Value = game
					while workspace.GameOver.Value ~= true and Skip ~= true do
						wait()
						if workspace.SkipTurn.Value == true then
							Skip = true
							print("Skip!")
						end
					end
					Skip = false
					workspace.SkipTurn.Value = false
					Headband.Text = "Figure out and kill the monster. It is everybody (not the monster)'s turn. clue: " .. Clues[math.random(1, #Clues)]
					repeat
  						task.wait(0.1)
					until not Delay2
					workspace.MonsterTurn.Value = false
					workspace.LastVoted.Value = game
					while workspace.GameOver.Value ~= true and Skip ~= true do
						wait()
						if workspace.SkipTurn.Value == true then
							Skip = true
							print("Skip!")
						end
					end
					Skip = false
					workspace.SkipTurn.Value = false
					if workspace.GameOver.Value == true then
						if workspace.Lost.Value == true then
							Headband.Text = "The monster won. The monster was: " .. workspace.Fraud.Value.DisplayName
							workspace.Lose:Play()
						else
							Headband.Text = "The survivors win. The monster was: " .. workspace.Fraud.Value.DisplayName
							workspace.Win:Play()
						end
						for i, plr in pairs(game.Players:GetPlayers()) do
							plr:LoadCharacter()
						end
						wait(5)
						delay = false
						delay4 = false
					end
				end
			end
			end
	end
end)

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		local Prompt = Instance.new("ProximityPrompt")
		local Attach = Instance.new("Attachment")
		Attach.Parent = Char.Head
		Attach.Position = Vector3.new(0, 3, 0)
		Prompt.Parent = Attach
		Prompt.RequiresLineOfSight = false
		Prompt.HoldDuration = 1
		Prompt.MaxActivationDistance = 7
		Prompt.ActionText = "Vote/Kill"
		Prompt.ObjectText = Player.DisplayName
		Prompt.Triggered:Connect(function(Plr)
			if ((Plr ~= Player and workspace.Fraud.Value ~= Plr and workspace.MonsterTurn.Value == false) or (workspace.Fraud.Value == Plr and workspace.MonsterTurn.Value == true)) and Player:HasTag("Ingame") and Plr:HasTag("Ingame") then
				Char:BreakJoints()
				if Player:HasTag("Ingame") then
					Player:RemoveTag("Ingame")
					workspace.LastVoted.Value = Player
					workspace.SkipTurn.Value = true
					for i, bp in pairs(Char:GetChildren()) do
						if bp:IsA("BasePart") then
							bp.Color = Color3.fromRGB(255, 0, 4)
						end
					end
					workspace["Scare Stings 11"]:Play()
				end
			end
		end)
	end)
end)
local Delay2 = false
workspace.LastVoted.Changed:Connect(function(E)
	workspace.LastVoted.Value = nil
	if Delay2 == false then
		Delay2 = true
		plrs = 0
		workspace.Lost.Value = true
		for i, plr in pairs(game.Players:GetPlayers()) do
			if plr:HasTag("Ingame") then
				plrs += 1
			end
			if plr == workspace.Fraud.Value and not plr:HasTag("Ingame") then
				workspace.Lost.Value = false
				workspace.GameOver.Value = true
			end
		end
		if plrs < 3 then
			workspace.GameOver.Value = true
		end
		Delay2 = false
	end
end)

Let me know if you run into any problems with that.
While I anticipate this to fix one of the problems with your script, it likely won’t be a magical fix that will make it automatically start working. I’m sure there will be a few other things that are causing issues, but we can do it!!

Hello, checking back in! Did that work, or is there something else going on now?

its not fixed sadly…
the problem now is that it wont start because “not enough players” and it wont change no matter the player count
it gets stuck right there

After a quick glance, it seems like the reason is because the function connected to the Heartbeat event runs once at runtime, and because the player count isn’t high enough, it displays the “Not Enough Players.” message. However, it will never perform that check again, as you set delay = true and forgot to set it back to false after. You should add delay = false after these lines:

Headband.Text = "Not Enough Players."
wait(3)

im gonna test it
lets hope it wooooooooorks!

didnt work :frowning:
same failure as last time
just doesnt let the turn change