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

How to make a script compatible for multiple players?

Asked by 10 years ago

Okay i'm making a game which has rounds. I scripted the round system but it only works with one player. How can I make this work when there are multiple players on the server. By work I mean make all the timers the same for every player whose in the game.

Here's my script:

game.Players.PlayerAdded:connect(function(player)
    function intermission()
        game.workspace.Music:Play()
        GUI = player.PlayerGui:WaitForChild'Intermission'.Frame
        NewsGUI = player.PlayerGui.NewsBar.Frame
        NewsGUI.Visible = true
        Second = GUI.Seconds
        GUI.Visible = true
            for i = 45,1, -1 do
                Second.Text = i
                wait(1)
                  if Second.Text == "1" then
                   map = game.Lighting:FindFirstChild("MAP1"):clone()
                   map.Parent = game.workspace
                   map:MakeJoints()
                   GUI.Seconds.Text = " "
                   GUI.Title.Text = "Loading Map"
                   wait(7)
                   player.Character.Torso.CFrame = CFrame.new(Vector3.new(967.119, 41.396, -391.16))
                    RoundBegin()
                  end
            end
    end

    function RoundBegin()
        GUI = player.PlayerGui:WaitForChild'Intermission'.Frame
        GUI2 = player.PlayerGui:WaitForChild'StartRound'.Frame
        GUI3 = player.PlayerGui:WaitForChild'RoundTime'.Frame
        NewsGUI = player.PlayerGui.NewsBar.Frame
        game.workspace.Music:Stop()
        game.workspace.RoundMusic:Play()
        Second2 = GUI2.BeginTime
        Second3 = GUI3.TextLabel
        GUI.Title.Text = "Intermission"
        GUI.Visible = false
        GUI2.Visible = true
        NewsGUI.Visible = false
        for i = 5,1, -1 do
            Second2.Text = i
            wait(1)
              if Second2.Text == "1" then
                GUI3.Visible = true 
                GUI2.Visible = false
                game.Workspace.RoundMusic:Stop()
                  for i = 300,1, -1 do
                    Second3.Text = i
                    wait(1)
                end
                RoundEnd()
            end
        end

    end

    function RoundEnd()
        GUI3 = player.PlayerGui:WaitForChild'RoundTime'.Frame
        GUI4 = player.PlayerGui:WaitForChild'RoundEnd'.Frame

        GUI3.Visible = false
        GUI4.Visible = true         
        map:Destroy()
        player.Character.Torso.CFrame = CFrame.new(Vector3.new(4, 4.938, -53.5))
        wait(5)
        GUI4.Visible = false

        intermission()
    end

    intermission()
end)

1 answer

Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
10 years ago

Well you're editing their timer when they join, just use a for loop and get all the Players from it and use it to edit the GUI in their PlayerGui eg -

function intermission()
        game.workspace.Music:Play()
    for i,v in pairs(game.Players:GetPlayers()) do
        GUI = v.PlayerGui:WaitForChild'Intermission'.Frame
        NewsGUI = v.PlayerGui.NewsBar.Frame
        NewsGUI.Visible = true
        Second = GUI.Seconds
        GUI.Visible = true
            for i = 45,1, -1 do
                Second.Text = i
                wait(1)
                  if Second.Text == "1" then
                   map = game.Lighting:FindFirstChild("MAP1"):clone()
                   map.Parent = game.workspace
                   map:MakeJoints()
                   GUI.Seconds.Text = " "
                   GUI.Title.Text = "Loading Map"
                   wait(7)
                   player.Character.Torso.CFrame = CFrame.new(Vector3.new(967.119, 41.396, -391.16))
                    RoundBegin()
                  end
            end
    end

Although correct me if I'm wrong as I have not tested and not scripted in a while, please excuse me if it is wrong, but if not, I hope it helped.

0
Okay i'll try it but I have one question if I take the game.Players.PlayerAdded:connect(function(player) out won't all the Player. part of the code be nil? austin10111213 28 — 10y
0
You would need to define player in the loop. Ryzox 220 — 10y
Ad

Answer this question