Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is a good way to make a round system?

When I try to make a round system (like mad murderer, phantom forces, ect.) I always get lost on how to make it a continuous loop. I am pretty sure while loops and repeats are useful when making these types of scripts but I need a little help on how I could do this.

Here is one of my unfinished scripts.

local gameFolder = game.ReplicatedStorage.Game
local events = game.ReplicatedStorage.Events
local playersInMatch = gameFolder.PlayersInGame
local currentTime = gameFolder.CurrentTime
local playersInServer = gameFolder.Players
local gameInProgress = gameFolder.GameInProgress

minimumPlayers = 4
xpReward = 10
creditsReward = 5
intermissionTime = 45
gameTime = 120
	
playersInServer.Changed:Connect(function()
	if playersInServer.Value >= minimumPlayers then
		
		while playersInServer.Value < minimumPlayers do
			wait(1)
		end
		
		currentTime.Value = intermissionTime
		
		repeat currentTime.Value = currentTime.Value - 1
			wait(1)
		until playersInServer.Value < minimumPlayers or currentTime.Value == 0 
	
	--Start Game
	if currentTime.Value == 0 and playersInServer.Value >= minimumPlayers then
		
		events.GameStart:FireAllClients()
		
		local player = game.Players:GetChildren()
for i = 1, #player do
	if player.Stats.AFK.Value == false then
	local playerTag = Instance.new("StringValue")
	playerTag.Value = player.Name
	playerTag.Parent = gameFolder.PlayerList
	
	playersInMatch.Value = playersInMatch.Value + 1
	player.Character.Humanoid.Torso.CFrame = CFrame.new(0,3,0)
	player.Character.Humanoid.WalkSpeed = 20
	player.Character.JumpPower = 40
	player.InGame.Value = true
end

wait(5)

local player = game.Players:GetChildren()
for i = 1, #player do
	player.Character.FF:Destroy()
end

currentTime.Value = gameTime.Value
gameInProgress.Value = true
end
	end
	else
		return
	end
	
end)

--Win
playersInMatch.Changed:Connect(function()
	
	if playersInMatch.Value == 1 and gameInProgress.Value == true then
		
		playersInMatch.Value = 0
		
		local player = game.Players:GetChildren()
for i = 1, #player do
	
    if player.InGame.Value == true then
	player.Stats.XP.Value = player.Stats.XP.Value + xpReward
	player.Stats.Credits.Value = player.Stats.Credits.Value + creditsReward
	events.Win:FireAllClients(player.Name)
else
	player.Stats.XP.Value = player.Stats.XP.Value + 1
end
end

wait(5)
events.Reset:FireAllClients()

end	
end)

As you can see it is very unorganized and doesn't even loop. I understand how to teleport characters, reward people, and all that stuff. It seems simple when I think of it but once i start scripting everything gets unorganized and confusing. If anyone could possibly give me a simplified example or a list that'd be great. Thank you.

1 comment

0

lastTick = tick() while true do wait() print(lastTick-tick()) end -- now all u gotta do is turn it into a timer interface..

1 answer

✓ Accepted answer

Hm, Really Good Question. When i usually go about scripting something, I like to think what I'm doing, why I'm doing it, and how to go about it (Basically meaning do you research first.). So, lets go about thinking on how to start. We need something to countdown to each round right? Let's have a script do that. So how do we countdown time? Well, there are multiple ways. One being os.time() (Usually Preferred). And tick() or....Count! e.g.(thing = thing + 1). Now, when do we start counting down? Well, have check function where a player is added, it check whether there are enough players to start the count. If there is, we count down. Once the countdown is complete, we loop through the players grab the characters, and reposition their root part cframes. Now this same server script starts counting down again (For, however long the round is.). Once it finishes counting down, we loop through the players again and grab the characters root parts cframe, then reposition that cframe back to the lobby. That at-least is the basics of what you might wanna do, excluding winning rewards etc.. How do you not get confused? What helps me is writing down my thoughts, and keeping those in mind. While scripting. And writing down new thoughts if they come to mind (Keeping your thoughts organized.). Anyways, sorry if this got a bit to long. Hope that it Helped slightly.

This discussion is preserved as it was. New answers, comments, and votes are closed.