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)
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)
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)
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
(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