Timer GUI for Players acting weirdly

  1. What do I want to achieve? So basically there is a hider and the others finders i want to start a timer for them

  2. What is the issue? So basically the timer is acting weird i will show by a video -

  1. What solutions have I tried so far? Yes I did but as i searched i did not find anything

So now i will show my code -

--Length Variables
local roundLength = game.ReplicatedStorage.roundLength
local gameStartLength = game.ReplicatedStorage.gameStartLength


game.Players.PlayerAdded:Connect(function(player)
    wait(10)
    
    -- Player Count
    local playerCount = #game.Players:GetPlayers()

    --Game Status 
    local gameStatus = game.ReplicatedStorage.gameStatus
    gameStatus.Value = "Waiting for Game to Start..."
    
    --Round Status 
    local roundStatus = player.PlayerGui:WaitForChild("InRound")
    
    --Guis
    local bgFinderHider = player.PlayerGui.Bg
    local finderHiderChoosingFrame = player.PlayerGui.HiderFinderGui.FinderBGGui
    
    --Texts
    local hiderFinderText = finderHiderChoosingFrame.Frame.TextLabel
    
    --Starting Game
    while wait() do
        
        --Checking if there are enough players to Start the Game
        if playerCount >= 1 then
            for i = gameStartLength.Value,0,-1 do
                
                roundStatus.Value = false
                wait(1)
                gameStatus.Value = "Game Starts in "..i.." Seconds"
                bgFinderHider.Enabled = false
                
            end
            
            -- choosing a hider from the players in the game
            local hider = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
            
            print(hider.Name)
            
            bgFinderHider.Enabled = true
            

            finderHiderChoosingFrame:TweenPosition(
                UDim2.new(0.258,0,0.2,0),
                "In",
                "Quad",
                1,
                false
            )
            
            --TypeWriter Function
            local function typeWrite(object, text) 
                for i = 1,#text,1  do
                    wait(0.3)
                    object.Text = string.sub(text,1,i)
                end
            end
            
            wait(2)
            
            -- Checking if player is a hider or not and showing them the text
            if player ~= hider then

                typeWrite(hiderFinderText, 'Finder')

            else

                typeWrite(hiderFinderText, 'Hider')

            end
            
            
            
            wait(5)
            
            finderHiderChoosingFrame:TweenPosition(
                UDim2.new(0.258,0,1,0),
                "Out",
                "Quad",
                1,
                false
            )
            
            wait(1)
            
            hiderFinderText.Text = ""
            
        else
            gameStatus.Value = "Waiting for Enough Players..."
        end
    end
    
end)

this script is inside severscriptservice just telling :sweat_smile:

Hope you guys can hep me :frowning:

2 Likes

If anyone has any idea why it is like that, then please tell me :frowning:! I m looking to find a way for this for more than 3 days!

2 Likes

You are running that code whenever a new player joins - so if 5 players have joined, you’re going to have the code for starting the game running 5 times.

3 Likes

so what i m supposed to do then ?

1 Like

can i replace the whole while loop inside in a for loop like this:

for player in pairs(game.Players:GetChildren()) do

  -- Player Count
    local playerCount = #game.Players:GetPlayers()

    --Game Status 
    local gameStatus = game.ReplicatedStorage.gameStatus
    gameStatus.Value = "Waiting for Game to Start..."
    
    --Round Status 
    local roundStatus = player.PlayerGui:WaitForChild("InRound")
    
    --Guis
    local bgFinderHider = player.PlayerGui.Bg
    local finderHiderChoosingFrame = player.PlayerGui.HiderFinderGui.FinderBGGui
    
    --Texts
    local hiderFinderText = finderHiderChoosingFrame.Frame.TextLabel
    
    --Starting Game
    while wait() do
        
        --Checking if there are enough players to Start the Game
        if playerCount >= 1 then
            for i = gameStartLength.Value,0,-1 do
                
                roundStatus.Value = false
                wait(1)
                gameStatus.Value = "Game Starts in "..i.." Seconds"
                bgFinderHider.Enabled = false
                
            end
            
            -- choosing a hider from the players in the game
            local hider = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
            
            print(hider.Name)
            
            bgFinderHider.Enabled = true
            

            finderHiderChoosingFrame:TweenPosition(
                UDim2.new(0.258,0,0.2,0),
                "In",
                "Quad",
                1,
                false
            )
            
            --TypeWriter Function
            local function typeWrite(object, text) 
                for i = 1,#text,1  do
                    wait(0.3)
                    object.Text = string.sub(text,1,i)
                end
            end
            
            wait(2)
            
            -- Checking if player is a hider or not and showing them the text
            if player ~= hider then

                typeWrite(hiderFinderText, 'Finder')

            else

                typeWrite(hiderFinderText, 'Hider')

            end
            
            
            
            wait(5)
            
            finderHiderChoosingFrame:TweenPosition(
                UDim2.new(0.258,0,1,0),
                "Out",
                "Quad",
                1,
                false
            )
            
            wait(1)
            
            hiderFinderText.Text = ""
            
        else
            gameStatus.Value = "Waiting for Enough Players..."
        end
    end 

end
1 Like

when i used that with a for loop get children and get players, i got a error like:

22:15:01.976 ServerScriptService.RoundSystem:21: attempt to index number with ‘PlayerGui’ - Server - RoundSystem:21
22:15:01.977 Stack Begin - Studio
22:15:01.977 Script ‘ServerScriptService.RoundSystem’, Line 21 - Studio - RoundSystem:21
22:15:01.977 Stack End - Studio

as they are retuning a number : /

1 Like

My Current Code is this and this return a number :frowning:

--Length Variables
local roundLength = game.ReplicatedStorage.roundLength
local gameStartLength = game.ReplicatedStorage.gameStartLength


while wait() do
	
	for player in pairs(game.Players:GetPlayers()) do


		wait(10)

		-- Player Count
		local playerCount = #game.Players:GetPlayers()

		--Game Status 
		local gameStatus = game.ReplicatedStorage.gameStatus
		gameStatus.Value = "Waiting for Game to Start..."

		--Round Status 
		local roundStatus = player.PlayerGui:WaitForChild("InRound")

		--Guis
		local bgFinderHider = player.PlayerGui.Bg
		local finderHiderChoosingFrame = player.PlayerGui.HiderFinderGui.FinderBGGui

		--Texts
		local hiderFinderText = finderHiderChoosingFrame.Frame.TextLabel

		--Starting Game
		while wait() do

			--Checking if there are enough players to Start the Game
			if playerCount >= 1 then
				for i = gameStartLength.Value,0,-1 do

					roundStatus.Value = false
					wait(1)
					gameStatus.Value = "Game Starts in "..i.." Seconds"
					bgFinderHider.Enabled = false

				end

				-- choosing a hider from the players in the game
				local hider = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]

				print(hider.Name)

				bgFinderHider.Enabled = true


				finderHiderChoosingFrame:TweenPosition(
					UDim2.new(0.258,0,0.2,0),
					"In",
					"Quad",
					1,
					false
				)

				--TypeWriter Function
				local function typeWrite(object, text) 
					for i = 1,#text,1  do
						wait(0.3)
						object.Text = string.sub(text,1,i)
					end
				end

				wait(2)

				-- Checking if player is a hider or not and showing them the text
				if player ~= hider then

					typeWrite(hiderFinderText, 'Finder')

				else

					typeWrite(hiderFinderText, 'Hider')

				end



				wait(5)

				finderHiderChoosingFrame:TweenPosition(
					UDim2.new(0.258,0,1,0),
					"Out",
					"Quad",
					1,
					false
				)

				wait(1)

				hiderFinderText.Text = ""

			else
				gameStatus.Value = "Waiting for Enough Players..."
			end
		end




	end


	
end
1 Like

Question, why is your typewriting script inside your Server script? Or am i reading that wrong?

I would use a IntValue instead, and have the server count it down. Then on the client,

local Value = game.ReplicatedStorage.Timer
local Object = YourTextLabel
local function typeWrite(object, text)
for i = 1,#text,1 do
wait(0.3)
object.Text = string.sub(text,1,i)
end
end
--The next function is to change the timer when it is needed.

Value.Changed:Connect(function() -- This is a basic example, what you would need to do is concentrate your string and number value. (Value.Value .. " is how much time is left")
typeWrite(Object, Value.Value)

end

The above code would only work if you changed the timer value on the serverside.

Hope this helps,
-Warrior

1 Like

problem is not with typewriting function : /
its with the gui

2 Likes

I know it isnt with the TypeWriter. Please read my above statement. It says that the script is for the Client to find when a value is changed by the serverside, and then update the player’s GUI accordingly.

2 Likes

yes it is and it works correctly

2 Likes

The issue is that something is making the TypeWrite function run more than once. That being said, i think you should try out my script. Therefore when the SERVER changes the timer value, the CLIENT notices only once. It then changes according to the time left in the value.

3 Likes

Bro listen, where that function call is like when the game chooses a person, a GUI appears and on that, a text is written with this effect. Now my problem is another like that GUI shows for only one person : /

1 Like

@Warriorgamer7777 this s the aother post i made like thats the current problem :frowning:
post link: For One Person Only GUI Appears in the Game

1 Like