How To Make A Countdown Timer That Only Certain Players Can See

I’m trying to make a game countdown timer. The part I’m having trouble with is making only the players in the table have the countdown timer.

Here’s the script that I tried making but it’s probably inefficient and it doesn’t work

Script (shortened)

local plrs = {} --The table is not empty the part of my script where I add the players to the table is just edited out

for i, Player in pairs(plrs) do
	game.ReplicatedStorage.Time:FireClient(player)
end

local script

local gameLength = 150

game.ReplicatedStorage.Time.OnClientEvent:Connect(function()
	for i = gameLength,0,-1 do
		gameLength = gameLength - 1
		script.Parent.Text = gameLength
		wait(1)
		
	end
	
end)

I’m not trying to advertise but are you looking for something similar to this in my game:
https://www.roblox.com/games/5287907627/UPDATE-1-4-Timed-Obby?refPageId=85b64b15-7ee3-4b03-8b1a-15cb0d5f8afb

If so I can help you.

Try this something like this with an intvalue.

repeat
wait(1)
Script.Parent.Value.Value = Script.Parent.Value.Value - 1
until
script.Parent.Value.Value = 0

And in the localscript you can use changed like this:
game.ReplicatedStorage.Value.Changed:Connect(function(change)
script.Parent.TextLabel.Text = change

(I typed this on my iphone so expect some mistakes)

3 Likes

Variables are case sensitive. you used Player as your i,_ but returned player through your remote event.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local plrs = {}
for i,player in pairs(plrs) do
	ReplicatedStorage.Time:FireClient(player)
end

then in your local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local gameLength = 150

ReplicatedStorage.Time.OnClientEvent:Connect(function()
	for i = 1,150 do
        gameLength -= 1 -- increment down by 1 every second
        script.Parent.Parent.Enabled = true
		script.Parent.Text = gameLength        
		wait(1)		
	end	
end)
1 Like

Is there any way to make it so only the players in the table can see the time?

You can instance a value in every player and insert a localscript wich watches what the value in the player tells the countdown.

1 Like

So I did what you said, but I had a script that changed all of the players in the tables IntValue. However when more than one player is in the table it doesn’t work.

for i = 1, 150 do
	for i, player in pairs(plrs) do
		local plr = game.Players:FindFirstChild(player.Name)
		
		plr.gameTime.Value -= 1
	end
	wait(1)
	end

Copy what I said and it will work

(I couldn’t understand but is this what you were looking for?)
Insert a string value inside the player you want them to see (I am naming it InGame.)Just an example.

I have edited the script

Now type this script.

game.ReplicatedStorage.Time.OnClientEvent:Connect(function(player) 
	if player:FindFirstChild("InGame") then -- checks if the player has the InGame String in their

         for i = gameLength,0,-1 do
		gameLength = gameLength - 1
		script.Parent.Text = gameLength
		wait(1)
		
        end
	
    end)
 end

Sorry if this wasn’t what you asked for.I’m not that of an expert.
So sorry :frowning:

1 Like