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

Why does it only work when I play by myself?(unanswered)

I have two separate pieces of script here. Basically it displays a message if the team "survivors" has no players left(waitforwinner function). It works only when a single player is on but when I tried to play with someone who else at the same time it failed to display the message

function Waitforwinner()	
wait(420)
if #getTeam(game.Teams.Survivors) >= 1  then
local m = Instance.new("Message", Workspace)
m.Text = "Time has run out. Survivors win!"
wait(3)
m:Destroy()

for i,v in pairs(game.Players:GetPlayers()) do
			v.Character.Humanoid.Health = 0
			v.TeamColor = BrickColor.new("Bright blue")
			wait(5)			
			v.Character.Humanoid.WalkSpeed = 0
		begin("Beginning the round now!You will have 15 seconds before a player is randomly infected.",3)--function begin
		respawn()
		FirstInfected("A player has been randomly infected!",3)
		waitforwinner()
		waitForWinner()
end
end
end

function waitforwinner()
if #getTeam(game.Teams.Survivors) == 0 then
		m = Instance.new("Message",Workspace)
			m.Text = "The final survivor was infected. Once you respawn the round will begin!"
		wait(3)
	m:Destroy()			
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.TeamColor == BrickColor.new("Bright orange") then
			v.StarterGear.Revolver:remove()
		end
			v.Character.Humanoid.Health = 0
			wait(1)
			v.TeamColor = BrickColor.new("Bright blue")
			wait(5)			
		begin("The round has begun.",3)
		GiveGun()
		FirstInfected("A player has been randomly infected!",3)
		waitforwinner()
		waitForWinner()
		end
		end
end

waitforwinner()
waitForWinner()

Any reasons why this wouldn't work? Thanks

1 answer

One thing I noticed is that you have name calling the function different from naming the function

for example -- you wrote

Waitforwinner() - the W is capitalized
waitforwinner()	-- nothing is capitalized here


waitforwinner()	--nothing is capitalized in here
waitForWinner() -- the F is capitalized and the W is

These don't agree so i think you need to fix these and see if it helps.

Also I would call the first waitforwinner as it will start the game and then after 420 seconds it will call the other one.

3 comments

0

What do you mean?

0

@wjs3456 which message did if fail to print?

0

The final survivor was infected. Once you respawn the round will begin

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