Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
wjs3456 90
9 years ago

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

Log in to vote
0
Answered by 9 years ago

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.

0
What do you mean? wjs3456 90 — 9y
0
@wjs3456 which message did if fail to print? hockey1scool 10 — 9y
0
The final survivor was infected. Once you respawn the round will begin wjs3456 90 — 9y
Ad

Answer this question