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

Why isn't the if statement in my timer script working?

Why isn't the if statement working on line 19?

local timeint = 57
local inttime = 5
local gametill = 5
local status = game.ReplicatedStorage.Status

if game.ServerScriptService.PlayerCount.Players.Value>=2 then	
	for i = inttime,1,-1 do
		wait(1)
		status.Value = "Intermission: "..i.." seconds."
	end
	for i = gametill,1,-1 do
		status.Value = "Game starts in "..i.." seconds!"
		wait(1)
	end
	status.Value = "Capture the enemy's flag!"
	wait(3)
	for i = timeint,1,-1 do
		status.Value = "Game Time: "..i.." seconds."
		if status.Value ~= "Game Time: "..i.." seconds." then
			wait(10)
		end
		wait(1)	
	end
else
	status.Value = "Waiting for more players to join."
end

There's a different text that comes up and the gui doesn't wait 10 seconds.

3 comments

0

Is this a server script or a local script? Always important.

0

server script

0

for i=inttime,0,-1 do instead of for i=inttime,1,-1 do

1 answer

It probably does, just at the wrong times. This only checks once, and does not if another player joins. This has a simple fix. Use this.

local timeint = 57
local inttime = 5
local gametill = 5
local status = game.ReplicatedStorage.Status

game.Players.PlayerAdded:Connect(function()
	if #game.Players:GetPlayers() >= 2 then --Use your useful roblox functions, man.  
	    for i = inttime,1,-1 do
	        wait(1)
	        status.Value = "Intermission: "..i.." seconds."
	    end
	    for i = gametill,1,-1 do
	        status.Value = "Game starts in "..i.." seconds!"
	        wait(1)
	    end
	    status.Value = "Capture the enemy's flag!"
	    wait(3)
	    for i = timeint,1,-1 do
	        status.Value = "Game Time: "..i.." seconds."
	        if status.Value ~= "Game Time: "..i.." seconds." then
	            wait(10)
	        end
	        wait(1) 
	    end
	else
	    status.Value = "Waiting for more players to join."
	end
end)

Hope this helps!

6 comments

0

It still doesn't work

0

i've dealt with countdowns, use for i=inttime,0,-1 do instead

0

its not the countdown, its the if statement

0

Simple question. Are there 2 players?

0

I changed the script so that if I'm in there the timer starts

0

YOU COULD NOT ANSWER THE SIMPLE QUESTION?

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