Minigame Round Script Broken

  1. What do you want to achieve? Keep it simple and clear!

The wall will become invisible, the countdown will go down from 30 to 0. At 0 (or when someone touches the block at the end) the map will delete itself, it’ll say “Player has won the game”

  1. What is the issue? Include screenshots / videos if possible!
    The wall does become invisible. The timer stays at 30, you’re able to win it more than once.

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!

local brick = game.Workspace.WallMan
local status = game.ReplicatedStorage.Status
local maps = game.ReplicatedStorage.Maps:GetChildren()

while true do
	for i = 1,10 do
		status.Value = "Intermission " ..10-i
		wait(1)
	end
	local rand = math.random(1,#maps)

	local map = maps[rand]:Clone()
	map.Parent = workspace

	status.Value = "We'll be playing "..map.Name
	wait(4)

	local players = game.Players:GetChildren()
	for i =1,#players do
		if players[i].Character ~= nil then
			brick.Transparency = 1
			brick.CanCollide = false
			

		end
	end

	local roundLengh = 30
	local canWin = true

	if map:FindFirstChild("Obby") then
		map.EndPart.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid")and canWin == true then
				canWin = false
				status.Value = hit.Parent.Name.." has won!"

				local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
				plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value +1
				plr.leaderstats.Points.Value = plr.leaderstats.Points.Value +50

			end


		end)
	end

	repeat
		roundLengh = roundLengh -1
		status.Value = "Time Remaining:  "..roundLengh
		wait(1)
	until roundLengh == 0 or canWin	== false or #workspace.Ingame:GetChildren() == 0

	wait(30)
	map:Destroy()
	brick.Transparency = 0.65
	brick.CanCollide = true


	local players = game.Players:GetChildren()
	for i =1,#players do
		if players[i].Character ~= nil then
			players[i]:LoadCharacter()
		end
	end
end

Any help would be greatly appreciate it. I am quite rubbish at scripting so I will need a fair bit of explanation.

Hello. That script is actually quite good, however, it could use a few improvements and fixes for faster and more reliable operation. I will be explaining every single change I make to the original script, and I will also attach a copy of the final script. So, let us begin.


In cases like these, you are not recommended to use while true do loops. It is rather better to use Bindable Events in this case.

As you are making a countdown, you are recommended to do so in an inverse manner, using the Step parameter of the for-do loop.

In this case, you can use in pairs() function of the for-do loop.

Parenting the map to the workspace after the shown map time is over and the round has started would make it less glitchy.

I’m not quite sure what the motif of this block of code is, but I’m gonna assume that you are trying to make the brick visible if a player’s character is present. If that’s the case, I would recommend using break.

It is better to wait after destroying the map.


Final Script:

local brick = game.Workspace.WallMan
local status = game.ReplicatedStorage.Status
local maps = game.ReplicatedStorage.Maps:GetChildren()

local StartedEvent = Instance.new("BindableEvent")
StartedEvent.Name = "RoundStarted"
StartedEvent.Parent = game:GetService("ServerStorage")

local roundLengthInit = 5
local roundLength = roundLengthInit
local canWin = true

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"

local Wins = Instance.new("IntValue")
Wins.Value = 0
Wins.Name = "Wins"
Wins.Parent = leaderstats

local Points = Instance.new("IntValue")
Points.Value = 0
Points.Name = "Points"
Points.Parent = leaderstats

game.Players.PlayerAdded:Connect(function(Player)
	leaderstats:Clone().Parent = Player
end)

StartedEvent.Event:Connect(function()
	local RoundHasWinner = false
	for i = 10,1,-1 do
		status.Value = "Intermission " .. i
		wait(1)
	end
	
	local rand = math.random(1,#maps)

	local map = maps[rand]:Clone()
	
	status.Value = "We'll be playing "..map.Name
	wait(4)
	
	map.Parent = workspace
	
	for _,Player in pairs(game.Players:GetPlayers()) do
		if Player and Player.Character and Player.Character:FindFirstChild("Humanoid") then
			brick.Transparency = 1
			brick.CanCollide = false
			break
		end
	end
	
	if map:FindFirstChild("Obby") then
		map.EndPart.Touched:Connect(function(hit)
			if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and canWin == true then
				canWin = false
				RoundHasWinner = true
				status.Value = hit.Parent.Name.." has won!"

				local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
				plr.leaderstats.Wins.Value += 1
				plr.leaderstats.Points.Value += 50
				
				wait(3)

			end
		end)
		
	end
	
	while roundLength > 0 and canWin == true and #workspace.Ingame:GetChildren() > 0 do
		roundLength = roundLength -1
		status.Value = "Time Remaining:  "..roundLength
		wait(1)
	end 
	
	if not RoundHasWinner then status.Value = "Round has ended." end
	map:Destroy()
	wait(30)
	brick.Transparency = 0.65
	brick.CanCollide = true
	canWin =true
	roundLength = roundLengthInit
	
	
	for _,Player in pairs(game.Players:GetPlayers()) do
		if Player and not Player.Character then
			Player:LoadCharacter()
		end
	end
	
	StartedEvent:Fire()
	
end)

StartedEvent:Fire()

I hope this helps. Let me know if it does not. :slightly_smiling_face:

PS: I have tested it, and it works perfectly, thus if you see any errors, it might be the hierarchy.

1 Like

Thank you so much for all your help, this is the most help I’ve ever gotten!
You’re amazing!!

1 Like

Hey bud, doesn’t seem to be working!
Can you help me in DevForum DMs.