Script need's to run only once

  1. What do you want to achieve?

I want to make a fully working player round system. This is only one of the scripts.

  1. What is the issue? Include screenshots / videos if possible!

The issue is that I want the round system to only run once(the moment the player joins), and the intermission timer shouldn’t reset everytime the player dies.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried putting everything into function’s and running the function. I also have a intermission timer for my script but it resets every time the player dies. This script is located inside a text label. I’ve looked through a lot of articles in Developer forum. but they didn’t seem to help me. If there is a article to solve my problem, it would greatly be appreciated.
    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 function Hi()
	for i = 80,0,-1 do
		local Minute = math.floor(i/60)
		local Seconds = math.floor(i%60)
		if Seconds < 10 then
			Seconds = "0"..math.floor(i%60)
		end
		script.Parent.Text = Minute..":"..Seconds
		wait(1)
	end
end
Hi()
local function RoundSystem()
	local BluetTeam = {}
	local RedTeam = {}
	script.Parent = game.ServerScriptService
	local function ShuffleAllPlauyers(AllPlayers)
		local AllPlayersClone = {unpack(AllPlayers)}

		for i  = 1, #AllPlayers do
			AllPlayers[i] = table.remove(AllPlayersClone, math.random(#AllPlayersClone))
		end
		return AllPlayers
	end
	local TableForAllPlayers = {}
	for i,v in pairs(game.Players:GetPlayers()) do
		table.insert(TableForAllPlayers, v.Name)
	end
	local ShuffledPlayers = ShuffleAllPlauyers(TableForAllPlayers)
	for i =1, math.ceil(#ShuffledPlayers/2) do
		table.insert(RedTeam, ShuffledPlayers[i])
		table.remove(ShuffledPlayers, i)
	end
	for i,v in pairs(ShuffledPlayers) do
		table.insert(BluetTeam, v)
	end
	local RedTeamSapwn = game.Workspace:WaitForChild("SpawnPointsRedTeam")
	local BlueTeamSpawn = game.Workspace:WaitForChild("SpawnPointsBlueTeam")
	for NumberValue,v in pairs(RedTeam) do
		local Character = game.Workspace:WaitForChild(v)
	--[[	if Character.LeftHand then
			Character.HumanoidRootPart.Anchored = true
			Character.Head.Anchored = true
			Character.LeftHand.Anchored = true
			Character.LeftFoot.Anchored = true
			Character.LeftLowerArm.Anchored = true
			Character.LeftLowerLeg.Anchored = true
			Character.LeftUpperArm.Anchored = true
			Character.LeftUpperLeg.Anchored = true
			Character.LowerTorso.Anchored = true
			Character.RightFoot.Anchored = true
			Character.RightHand.Anchored = true
			Character.RightLowerArm.Anchored = true
			Character.RightLowerLeg.Anchored = true
			Character.RightUpperArm.Anchored = true
			Character.UpperTorso.Anchored = true
			Character.Head.Anchored = true
		else
			Character.Head.Anchored = true
			Character.HumanoidRootPart.Anchored = true
			Character["Left Arm"].Anchored = true
			Character["Right Arm"].Anchored = true
			Character.Torso.Anchored = true
			Character.LeftLeg.Anchored = true
			Character.RightLeg.Anchored = true
		end]]
		if #RedTeam == 1 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  RedTeamSapwn:FindFirstChild("Part1").Position + Vector3.new(0,5,0)
		end
		if #RedTeam == 2 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  RedTeamSapwn:FindFirstChild("Part"..NumberValue).Position + Vector3.new(0,5,0)

		end
		if #RedTeam == 3 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  RedTeamSapwn:FindFirstChild("Part"..NumberValue).Position+ Vector3.new(0,5,0)

		end
		if #RedTeam == 4 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  RedTeamSapwn:FindFirstChild("Part"..NumberValue).Position+ Vector3.new(0,5,0)

		end
		if  #RedTeam == 5 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  RedTeamSapwn:FindFirstChild("Part"..NumberValue).Position+ Vector3.new(0,5,0)

		end
	end
	for NumberValue,v in pairs(BluetTeam) do
		local Character = game.Workspace:WaitForChild(v)
	--[[	if Character.LeftHand then
			Character.HumanoidRootPart.Anchored = true
			Character.Head.Anchored = true
			Character.LeftHand.Anchored = true
			Character.LeftFoot.Anchored = true
			Character.LeftLowerArm.Anchored = true
			Character.LeftLowerLeg.Anchored = true
			Character.LeftUpperArm.Anchored = true
			Character.LeftUpperLeg.Anchored = true
			Character.LowerTorso.Anchored = true
			Character.RightFoot.Anchored = true
			Character.RightHand.Anchored = true
			Character.RightLowerArm.Anchored = true
			Character.RightLowerLeg.Anchored = true
			Character.RightUpperArm.Anchored = true
			Character.UpperTorso.Anchored = true
			Character.Head.Anchored = true
		else
			Character.Head.Anchored = true
			Character.HumanoidRootPart.Anchored = true
			Character["Left Arm"].Anchored = true
			Character["Right Arm"].Anchored = true
			Character.Torso.Anchored = true
			Character.LeftLeg.Anchored = true
			Character.RightLeg.Anchored = true
		end]]
		if #BluetTeam == 1 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  BlueTeamSpawn:FindFirstChild("Part1").Position + Vector3.new(0,5,0)
		end
		if #BluetTeam == 2 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  BlueTeamSpawn:FindFirstChild("Part"..NumberValue).Position + Vector3.new(0,5,0)

		end
		if #BluetTeam == 3 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  BlueTeamSpawn:FindFirstChild("Part"..NumberValue).Position+ Vector3.new(0,5,0)

		end
		if #BluetTeam == 4 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  BlueTeamSpawn:FindFirstChild("Part"..NumberValue).Position+ Vector3.new(0,5,0)

		end
		if  #BluetTeam == 5 then
			game.Workspace:WaitForChild(v):WaitForChild("HumanoidRootPart").Position =  RedTeamSapwn:FindFirstChild("Part"..NumberValue).Position+ Vector3.new(0,5,0)

		end
	end
	local BarrierForPlayers = game.ReplicatedStorage:WaitForChild("Barrier")
	local function Barriers()
		for i,v in pairs(game.Workspace.SpawnPointsBlueTeam:GetChildren()) do
			if v:IsA("Part") then
				local CloneBarrier = BarrierForPlayers:Clone()
				CloneBarrier.Parent = workspace
				CloneBarrier.CFrame = v.CFrame * CFrame.new(Vector3.new(-CloneBarrier.Size.Y/2,0,0), Vector3.new(-17,180,0))
			end
		end
	for i,v in pairs(game.Workspace.SpawnPointsRedTeam:GetChildren()) do
		if v:IsA("Part") then
			local CloneBarrier = BarrierForPlayers:Clone()
			CloneBarrier.Parent = workspace
			CloneBarrier.CFrame = v.CFrame * CFrame.new(Vector3.new(-CloneBarrier.Size.Y/2,0,0), Vector3.new(-17,180,0))
		end
		end
	end
	Barriers()
end

RoundSystem()

– The moment this intermisson timer hits zero, the round system will run, but if player dies it resets.

If you’d like certain code to only run when a round is in progress, then you could do this:

Create a boolValue somewhere in your explorer and name it something like “roundInProgress”. Make it so that it switched to true when a round begins, and to false once a round ends. Then you can wrap whatever code you want in something like this:

if roundInProgress.Value == true then
    -- Code here
end

Why do it this way? Because that boolValue in your game is global to any scripts or localscripts (that is, if it’s in Workspace or ReplicatedStorage, for example), so you can base other features of your system(s) on those values. The same principle can be used for other features/systems in your game.

Alright, I’ll try this ans see if it works.

How woud I fix the timer from not resetting?

Dumb questions:

  • What kind of script is this?
  • Where is this script located (Full path)?

EDIT: Yeah I can see the problem already. I just need your answer OP for confirmation.

EDIT 2: Since OP isn’t answering. I presume this is a LocalScript inside a ScreenGui.blablabla.TextLabel. Everytime you die, the ScreenGui and it’s descendants gets resetted (AKA: destroyed and copied again to PlayerGui, meaning it runs the code again). OP, this is bad practice.

It’s just a regular script(Not local script), because I need it to run the same for all clients. It’s located inside of the text label as I stated in the post.

If the text label is inside of startergui, the screengui resets each time you die. A solution you might want to try is to put a localscript in starterplayerscripts (which doesn’t reset) to do the timer and then another localscript in startergui to display it based on a boolvalue

https://developer.roblox.com/en-us/api-reference/class/StarterGui

Edit: I’m not sure if it’s better to handle the timer on the serverside or clientside, I’ll leave that up to you

Alright, I’ll try that, I will let you know if there’s something wrong

I have a question, say that I do start the timer using a local script from “starterplayerscripts” And it’s 1min 30 sec’s long. the timer keeps going but what if another player joins the server, wouldn’t the timer reset for that player that just joined?

Example:

Player1
Start of timer: 1:30
Player1 waits 30 seconds
Timer is at 1:00

Player 2 just joins
Would the timer be at 1:30 seconds or same as Player1(1:00)?

I edited my previous comment and I recommend you do the timer in a server script in serverscriptstorage, editing a intvalue inside of replicatedstorage or something

How would I access the timer from server scripts?

ReplicatedStorage can be accessed by both client and server scripts (because like the name suggests, it’s replicated haha)

You access the timer by doing a little something like

local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.TimerValue = 0

Alright, I’m gonna try it. Hopefully that works :slight_smile:

Alright, it worked thank you very much for the help. :wink:

Happy to help, feel free to mark my answer as the solution :wink: