Script not repeating how I want it to

Script:

local function resetRed()

	local children = workspace.RedTeam
	local parts = workspace.RedParts

	if #children:GetChildren() == 0 then
		print("No")
		return
	end

	local num = math.random(1, #parts:GetChildren())
	local randomplace = parts:GetChildren()[num]
	local randomplayernum = math.random(1, #children:GetChildren())
	local player1 = children:GetChildren()[randomplayernum]


	if workspace.RedTeam:GetChildren()[randomplayernum] and workspace.RedParts:GetChildren()[num] then


		if #parts:GetChildren() == 0 then
			randomplace.Parent = workspace.RedParts
			player1.Parent = workspace.RedTeam
			return
		end
		if #children:GetChildren() == 0 then
			randomplace.Parent = workspace.RedParts
			player1.Parent = workspace.RedTeam
			return
		end

		player1.PrimaryPart.CFrame = randomplace.CFrame

		children:GetChildren()[randomplayernum].Parent = game.Workspace.TPPlayersRed
		print("Still here")
		randomplace.Parent = game.Workspace.TPPartsRed
		print("Here")

		if #parts:GetChildren() == 0 then
			randomplace.Parent = workspace.RedParts
			player1.Parent = workspace.RedTeam
			return
		end
		if #children:GetChildren() == 0 then
			randomplace.Parent = workspace.RedParts
			player1.Parent = workspace.RedTeam
			return
		end

		if workspace.RedTeam:GetChildren()[randomplayernum] and workspace.RedParts:GetChildren()[num] then
			print("2")
			children = game.Workspace.RedTeam
			parts = game.Workspace.RedParts

			num = math.random(1, #parts:GetChildren())
			randomplace = parts:GetChildren()[num]

			randomplayernum = math.random(1, #children:GetChildren())
			player1 = children:GetChildren()[randomplayernum]
			player1.PrimaryPart.CFrame = randomplace.CFrame
			player1.Parent = workspace.TPPlayersRed
			randomplace.Parent = workspace.TPPartsRed
			if #parts:GetChildren() == 0 then
				randomplace.Parent = workspace.RedParts
				player1.Parent = workspace.RedTeam
				return
			end
			if #children:GetChildren() == 0 then
				randomplace.Parent = workspace.RedParts
				player1.Parent = workspace.RedTeam
				return
			end

			if children:GetChildren()[randomplayernum] and parts:GetChildren()[num] then
				print("3")
				children = game.Workspace.RedTeam
				parts = game.Workspace.RedParts

				num = math.random(1, #parts:GetChildren())
				randomplace = parts:GetChildren()[num]

				randomplayernum = math.random(1, #children:GetChildren())
				player1 = children:GetChildren()[randomplayernum]

				player1.PrimaryPart.CFrame = randomplace.CFrame

				randomplace.Parent = workspace.TPPartsRed
				player1.Parent = workspace.TPPlayersRed
				if #parts:GetChildren() == 0 then
					randomplace.Parent = workspace.RedParts
					player1.Parent = workspace.RedTeam
					return
				end
				if #children:GetChildren() == 0 then
					randomplace.Parent = workspace.RedParts
					player1.Parent = workspace.RedTeam
					return
				end
			end
		end
	end
end

local function resetBlue()
	local children = workspace.BlueTeam
	local parts = workspace.BlueParts

	if #children:GetChildren() == 0 then
		print("No")
		return
	end

	local num = math.random(1, #parts:GetChildren())
	local randomplace = parts:GetChildren()[num]
	local randomplayernum = math.random(1, #children:GetChildren())
	local player1 = children:GetChildren()[randomplayernum]


	if workspace.BlueTeam:GetChildren()[randomplayernum] and workspace.BlueParts:GetChildren()[num] then
		if #parts:GetChildren() == 0 then
			randomplace.Parent = workspace.BlueParts
			player1.Parent = workspace.BlueTeam
			return
		end
		if #children:GetChildren() == 0 then
			randomplace.Parent = workspace.BlueParts
			player1.Parent = workspace.BlueTeam
			return
		end
		player1.PrimaryPart.CFrame = randomplace.CFrame

		children:GetChildren()[randomplayernum].Parent = game.Workspace.TPPlayersBlue
		print("Still here")
		randomplace.Parent = game.Workspace.TPPartsBlue
		print("Here")

		if #parts:GetChildren() == 0 then
			randomplace.Parent = workspace.BlueParts
			player1.Parent = workspace.BlueTeam
			return
		end
		if #children:GetChildren() == 0 then
			randomplace.Parent = workspace.BlueParts
			player1.Parent = workspace.BlueTeam
			return
		end

		if workspace.BlueTeam:GetChildren()[randomplayernum] and workspace.BlueParts:GetChildren()[num] then
			children = game.Workspace.BlueTeam
			parts = game.Workspace.BlueParts

			num = math.random(1, #parts:GetChildren())
			randomplace = parts:GetChildren()[num]

			randomplayernum = math.random(1, #children:GetChildren())
			player1 = children:GetChildren()[randomplayernum]
			player1.PrimaryPart.CFrame = randomplace.CFrame
			player1.Parent = workspace.TPPlayersBlue
			randomplace.Parent = workspace.TPPartsBlue
			if #parts:GetChildren() == 0 then
				randomplace.Parent = workspace.BlueParts
				player1.Parent = workspace.BlueTeam
				return
			end
			if #children:GetChildren() == 0 then
				randomplace.Parent = workspace.BlueParts
				player1.Parent = workspace.BlueTeam
				return
			end

			if children:GetChildren()[randomplayernum] and parts:GetChildren()[num] then
				children = game.Workspace.BlueTeam
				parts = game.Workspace.BlueParts

				num = math.random(1, #parts:GetChildren())
				randomplace = parts:GetChildren()[num]

				randomplayernum = math.random(1, #children:GetChildren())
				player1 = children:GetChildren()[randomplayernum]

				player1.PrimaryPart.CFrame = randomplace.CFrame

				randomplace.Parent = workspace.TPPartsBlue
				player1.Parent = workspace.TPPlayersBlue
				if #parts:GetChildren() == 0 then
					randomplace.Parent = workspace.BlueParts
					player1.Parent = workspace.BlueTeam
					return
				end
				if #children:GetChildren() == 0 then
					randomplace.Parent = workspace.BlueParts
					player1.Parent = workspace.BlueTeam
					return
				end
			end
		end
	end
end

local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local minutesvalue = rep:WaitForChild("Minutes")
local secondsvalue = rep:WaitForChild("Seconds")
local minutes = 2
local seconds = 30

local function killAll()
	local allPlayers = game.Players:GetChildren()
	
	for i = 1, #allPlayers do
		allPlayers[i].Character.Humanoid.Health = 0
	end
end

while true do
	
	minutesvalue.Value = minutes
	secondsvalue.Value = seconds

	repeat
		if secondsvalue.Value <= 0 then
			minutesvalue.Value = minutesvalue.Value - 1
			secondsvalue.Value = 59
		else
			secondsvalue.Value = secondsvalue.Value - 1
		end
		wait(1)
		
		if secondsvalue.Value <= 0 and minutesvalue.Value <= 0 then
			game.Workspace.Ref.RefWhistle:Play()
			game.Workspace.Ref.GameOver:Play()

			game.Workspace.Ball.Position = Vector3.new(-2.5, 3.799, -4.5 )

			resetRed(); resetBlue()

			local red = game.Workspace.RedPoints
			local blue = game.Workspace.BluePoints

			local redwin = red.Value > blue.Value
			local bluewin = blue.Value > red.Value
			local tie = blue.Value == red.Value

			if redwin == true then
				game.Workspace.RedWins:FireAllClients()
				
				for i, v in pairs(game.Teams.Red:GetPlayers()) do
					v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value = v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value + 1
				end
			end

			if bluewin == true then
				game.Workspace.BlueWins:FireAllClients()
				for i, v in pairs(game.Teams.Blue:GetPlayers()) do
					v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value = v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value + 1
				end
			end

			if tie == true then
				game.Workspace.TieGame:FireAllClients()
			end
		end
	until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
end

It’s repeating, but if red wins at first, it will keep saying red wins eventhough blue’s value is higher.

Can you please put some print statements within the three if statements (redwin == true; bluewin == true; tie == true) with uniquely identifiable messages (you can just put “RedWins”, “BlueWins”, “Tie”).

Please tell us if the expected ones are outputed. It is possible that the issue is outside of the script, so we gotta check this first.

If you want help with a specific part of your script then please post that part instead of posting almost your entire game in here cause how are we gonna find your issue?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local timeDisplay --[[
    consider using one stringvalue instead of two.
    you can format the stringvalue to display the time remaining
]]
local isGameRunning = false
local timeRemaining = 150

local function killAllPlayers()
    for _, player in pairs(players:GetPlayers()) do
        if player.Character then
            player.Character:WaitForChild("Humanoid").Health = 0
        end
    end
end

local red = game.Workspace.RedPoints
local blue = game.Workspace.BluePoints

local redwin = red.Value > blue.Value
local bluewin = blue.Value > red.Value
local tie = blue.Value == red.Value

local function gameEnding()
    -- do stuff to end game
    -- lemme just write it out
    isGameRunning = false

    if redwin and not bluewin then
        
    end

    if bluewin and not redwin then
        
    end

    if tie then
        
    end
end

while isGameRunning do
    -- do stuff while game is running, else break
    if timeRemaining <= 0 then
        gameEnding()
        break
        -- you dont need to do this actually but eh
    end
    timeRemaining -= 1
    timeDisplay.Value = string.format("%02d:%02d", timeRemaining / 60, timeRemaining % 60)
    task.wait(1)
end

I won’t even bother myself to correct everything.

It’s already fixed by me.

If you’re not even gonna try to help me out, then I won’t even bother setting this to solved.
You can just read the script entirely, it’s not even that much. And I just found out it was inside of the script. Please stop complaining, if you don’t like the topic, just click off.

3 Likes

263 lines doesn’t seem too much to be honest. Especially when asking help for just a repeat loop.

You can close this topic. Now stop being arrogant.

bro stop coding this code is actually the worst thing ive seen since 2018
i bet you watch alvinblox

rblo dont ban me again pls :pray:

It doesn’t really matter for me if it’s bad, I used to watch AlvinBlox, but the tutorials aren’t that good anyways, so no I did not watch him for this script. I’m a beginner scripter, I just need it to work how I want it to, which it does. Not gonna spend more time making it how some random dude on a forum wants it, absolutely disgusting

3 Likes

I’m the arrogant one here? :laughing:

3 Likes

You’re being mad for no reason at all. I am simply implying that, if you want people to help you with something, then at least provide only what is wrong here, and not 263 lines that I can’t read because 1. It’s bloat, and 2. It’s nonsense. If you’ve fixed it by yourself then I am very much proud, however you did not have to go “uhhhh if you dont like the topic leave!” well I did.

I can be childish here, I may have used the wrong words, but anyone in the DevForum can agree that you didn’t have to post your entire game (which seems to be written in just one script, a bad practice) in here, when all you’re doing is asking for help with one single repeat loop (that, for no reason, you wrapped it around another loop).

I’ve even tried helping you format and that’s how you reply. It’s like “ohh i am the best here i am the best programmer i know better” well if I am telling you not to post everything then don’t. No one has time to read through hundreds of lines trying to figure out what your issue is, and no one has the time to argue with you either.

Mark your own reply as solved, this topic will close by itself, we leave, don’t see each other, and go on with our lives. Now stop replying.

I’ll stop replying after this, since I agree it’s nonsense.

The topic was about what the issue was, I couldn’t find it myself, that’s why I posted this. For people to help me find the issue and maybe fix it. This is not my whole game, this is one of the many script for my game. As said at the top, this is only to determine the winner of a round. I never said anything like me being the best programmer here, as I am not. I’m only a beginner that needs help with my script. And as you said, if you don’t have time to read through my code, just don’t help me as I have figured it out myself now.

You’re saying it’s hundreds of lines of code, but I was referring to the main part. Not the functions, as they only server for resetting the teams.

3 Likes

for people that play your game it will matter
its called performance

How would it change the ‘performace’ if it’s working exactly how I want it to?

3 Likes

it working how you want it to does not mean its optimised

Well it’s not causing lag or FPS drops for me. Keep in mind I also don’t have a that good pc, on phone or tablet it also does not work differently.

It’s exactly how I want it to, for me it’s good enough. No changes needed.

3 Likes

not causing lag still doesnt mean its optimised