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

Why is the text not changing for others?

Asked by 10 years ago
-- NinjoOnline --

map = game.ServerStorage.Maps:GetChildren()

while true do

--------------------------
-- Random map is chosen --
--------------------------  

    if game.Players.NumPlayers > 1 then
        game.StarterGui.Main.Header.MainText.Text = "Deciding what map to play"
        wait(3)
        game.StarterGui.Main.Header.MainText.Text = ""
        ranMap = math.random(1, #map)
        mapChosen = map[ranMap]
        game.StarterGui.Main.Header.MainText.Text = "Map Chosen: " .. mapChosen.Name
        wait(2)
        game.StarterGui.Main.Header.MainText.Text = ""
        mapChosenClone = mapChosen:Clone()
        mapChosenClone.Parent = game.Workspace.MapHolder
        wait(2)

------------------------
-- Picks random teams --
------------------------

        players = game.Players:GetChildren()

        teams = {"Bright red","Bright blue"}
        num = 1

        for i,v in pairs(players) do
            v.TeamColor = BrickColor.new(teams[num])
            num = num + 1
            if num > #teams then
                num = 1
            end
        end


---------------------------------
-- Teleport players to the map --
---------------------------------

        bspawn = mapChosenClone.BlueSpawn
        rspawn = mapChosenClone.RedSpawn

        for i,v in pairs(game.Players:GetPlayers()) do 
            name = v.Name
            check = game.Workspace:FindFirstChild(name)
            if v.TeamColor == BrickColor.new("Bright red") then
                if check then
                    checkHumanoid = check:FindFirstChild("Humanoid")
                    if checkHumanoid then
                        local distance = math.random(-4, 4);
                        check:MoveTo(rspawn.Position + Vector3.new(distance, distance, distance))
                    end
                end
            elseif v.TeamColor == BrickColor.new("Bright blue") then
                if check then
                    checkHumanoid = check:FindFirstChild("Humanoid")
                    if checkHumanoid then
                        local distance = math.random(-4, 4);
                        check:MoveTo(bspawn.Position + Vector3.new(distance, distance, distance))
                    end
                end
            end
        end


---------------------------
-- Round begins countdown --
---------------------------

        for i = 3, 1, -1 do
            game.StarterGui.Main.Header.MainText.Text = "Game begins in: " .. i
            wait(1)
            game.StarterGui.Main.Header.MainText.Text = ""
        end

-------------------------------
-- Countdown till round ends --
-------------------------------

        for i = 30, 1, -1 do
            game.StarterGui.Main.Header.MainText.Text = "Time left: " .. i
            wait(1)
            game.StarterGui.Main.Header.MainText.Text = ""
        end
        game.StarterGui.Main.Header.MainText.Text = "The round has ended"
        wait(1)
        game.StarterGui.Main.Header.MainText.Text = ""

------------------------------------        
-- Teleport players back to lobby --
------------------------------------

        for i,v in pairs(game.Players:GetPlayers()) do
            v.Character:MoveTo(Vector3.new(108, 11.19, -29))
        end
        wait(1)

---------------------
-- Destroy the map --
---------------------

        mapChosenClone:Destroy()

--------------------------------------------------
-- Needs to be 1 more player for round to begin --
--------------------------------------------------

    else
        game.StarterGui.Main.Header.MainText.Text = "You need 1 more player to join"
    end
    wait(1)
end

Ok so, this script pretty much tell the player that if their is more than 1 player on, then pick a random map. That works, but, the GUI that displays the text wont update. I started a server with 2 players, for P1 it says "You need 1 more player" and for P2 it says "Deciding what map to play". But on the server it changes and is working properly. Is something wrong, or do i need to start a real server and get a friend to play. Anyone help?

2 answers

Log in to vote
4
Answered by 10 years ago

When you want to change how a gui looks for every player, you shouldn't update the StarterGui, otherwise it won't update until they respawn. To make it change automatically, you will have to access the guis via PlayerGui which is inside each player. To do this, you will have to access each player's guis individually using a localscript. You will then need to use a server script to clone the map into the game, otherwise you'd end up crashing the game if each localscript were to do that.

player = game.Players.LocalPlayer
maintext = player.PlayerGui.Main.Header.MainText


while wait() do
 if game.Players.NumPlayers > 1 then
    maintext.Text = "Deciding what map to play"
        wait(3)
        maintext.Text = ""
        maintext.Text = "Map Chosen: " .. _G.mapChosen.Name
        wait(2)
        maintext.Text = ""
        wait(2)
    else maintext.Text = "You need 1 more player"
    end

This above script should be localscript and placed in the startergui.

map = game.ServerStorage.Maps:GetChildren()
_G.mapChosen = nil

while wait() do
    if game.Players.NumPlayers > 1 then
        wait(2)
            ranMap = math.random(1, #map)
            _G.mapChosen = map[ranMap]
        wait(3)
        mapChosenClone = _G.mapChosen:Clone()
            mapChosenClone.Parent = game.Workspace.MapHolder
    end
end

This above script should be a server script and placed in Workspace.

This may not entirely work, but this should be helpful.

------------------------ Update: Based on the fact that you posted the whole script now, I have made it so that it should work now as is. ------------------------

-- NinjoOnline --

map = game.ServerStorage.Maps:GetChildren()

while true do

--------------------------
-- Random map is chosen --
--------------------------  

    if game.Players.NumPlayers > 1 then
        for i,v in pairs(game.Players:GetPlayers()) do
        v.PlayerGui.Main.Header.MainText.Text = "Deciding what map to play"
    end
        wait(3)
     for i,v in pairs(game.Players:GetPlayers()) do
            v.PlayerGui.Main.Header.MainText.Text = ""
    end
        ranMap = math.random(1, #map)
        mapChosen = map[ranMap]
    for i,v in pairs(game.Players:GetPlayers()) do
            v.PlayerGui.Main.Header.MainText.Text = "Map Chosen: " .. mapChosen.Name
    end
        wait(2)
    for i,v in pairs(game.Players:GetPlayers()) do
            v.PlayerGui.Main.Header.MainText.Text = ""
    end
        mapChosenClone = mapChosen:Clone()
        mapChosenClone.Parent = game.Workspace.MapHolder
        wait(2)

------------------------
-- Picks random teams --
------------------------

        players = game.Players:GetChildren()

        teams = {"Bright red","Bright blue"}
        num = 1

        for i,v in pairs(players) do
            v.TeamColor = BrickColor.new(teams[num])
            num = num + 1
            if num > #teams then
                num = 1
            end
        end


---------------------------------
-- Teleport players to the map --
---------------------------------

        bspawn = mapChosenClone.BlueSpawn
        rspawn = mapChosenClone.RedSpawn

        for i,v in pairs(game.Players:GetPlayers()) do 
            name = v.Name
            check = game.Workspace:FindFirstChild(name)
            if v.TeamColor == BrickColor.new("Bright red") then
                if check then
                    checkHumanoid = check:FindFirstChild("Humanoid")
                    if checkHumanoid then
                        local distance = math.random(-4, 4);
                        check:MoveTo(rspawn.Position + Vector3.new(distance, distance, distance))
                    end
                end
            elseif v.TeamColor == BrickColor.new("Bright blue") then
                if check then
                    checkHumanoid = check:FindFirstChild("Humanoid")
                    if checkHumanoid then
                        local distance = math.random(-4, 4);
                        check:MoveTo(bspawn.Position + Vector3.new(distance, distance, distance))
                    end
                end
            end
        end


---------------------------
-- Round begins countdown --
---------------------------

        for i = 3, 1, -1 do
            game.StarterGui.Main.Header.MainText.Text = "Game begins in: " .. i
            wait(1)
            game.StarterGui.Main.Header.MainText.Text = ""
        end

-------------------------------
-- Countdown till round ends --
-------------------------------

        for i = 30, 1, -1 do
            game.StarterGui.Main.Header.MainText.Text = "Time left: " .. i
            wait(1)
            game.StarterGui.Main.Header.MainText.Text = ""
        end
        game.StarterGui.Main.Header.MainText.Text = "The round has ended"
        wait(1)
        game.StarterGui.Main.Header.MainText.Text = ""

------------------------------------        
-- Teleport players back to lobby --
------------------------------------

        for i,v in pairs(game.Players:GetPlayers()) do
            v.Character:MoveTo(Vector3.new(108, 11.19, -29))
        end
        wait(1)

---------------------
-- Destroy the map --
---------------------

        mapChosenClone:Destroy()

--------------------------------------------------
-- Needs to be 1 more player for round to begin --
--------------------------------------------------

    else
        game.StarterGui.Main.Header.MainText.Text = "You need 1 more player to join"
    end
    wait(1)
end
0
No this may or may not work. I have 1 main script. The main script chooses map, tps everyone, and all that. I need it so it will go in one script and not be a local. NinjoOnline 1146 — 10y
0
and what is a server script? NinjoOnline 1146 — 10y
0
I have just updated the script to the full script. NinjoOnline 1146 — 10y
1
I have added an updated section to the end of the post. It should work now. If it doesn't, it must be something that you have done. FearMeIAmLag 1161 — 10y
View all comments (3 more)
0
still dosent work NinjoOnline 1146 — 10y
0
It can't be me. This is the only script. It has always worked, choosing map, etc. Just the text. It is defiantly main.Header.MainText, etc. It just dosent update at all NinjoOnline 1146 — 10y
0
Are you sure you're not accessing the gui wrong or something? Open the game in play solo in studio and tell me what the output says. FearMeIAmLag 1161 — 10y
Ad
Log in to vote
-2
Answered by 10 years ago

You would actually want to use this function:

function M(mesag,tim,sho)
    for i,v in pairs(game.Players:GetChildren()) do
        if v.PlayerGui and v.PlayerGui.Main and v.PlayerGui.Main.Header.MainText then
            v.PlayerGui.MainGui.MESG.Visible = true
        v.PlayerGui.Main.Header.MainText.Text = mesag

        end
    end
wait(tim)
for i,v in pairs(game.Players:GetChildren()) do
        v.PlayerGui.Main.Header.MainText.Text = sho
        end
end

Just when you call the function do this

 M("Insert message here between parenthesis", 4--[[time you want it to show]], true--[[if you want it to show or disappear after the message is done being showed]])

so just in case you didn't get that, use parenthesis to put in text first, put a comma, how long you want it to show, another comma, and then true or false for it to become hidden or stay visible. I have my friend edit the script for you.

-- NinjoOnline --
--Edited by luis91899--

function M(mesag,tim,sho)
    for i,v in pairs(game.Players:GetChildren()) do
        if v.PlayerGui and v.PlayerGui.Main and v.PlayerGui.Main.Header.MainText then
            v.PlayerGui.MainGui.MESG.Visible = true
        v.PlayerGui.Main.Header.MainText.Text = mesag

        end
    end
wait(tim)
for i,v in pairs(game.Players:GetChildren()) do
        v.PlayerGui.Main.Header.MainText.Text = sho
        end
end
map = game.ServerStorage.Maps:GetChildren()

while true do

--------------------------
-- Random map is chosen --
--------------------------  

    if game.Players.NumPlayers > 1 then
        M("Deciding what map to play",3,false) -- says deciding what map to play for 3 seconds then      ----dissapears

        ranMap = math.random(1, #map)
        mapChosen = map[ranMap]
      M("Map Chosen: " .. mapChosen.Name, 2, false)


        mapChosenClone = mapChosen:Clone()
        mapChosenClone.Parent = game.Workspace.MapHolder
        wait(2)

------------------------
-- Picks random teams --
------------------------

        players = game.Players:GetChildren()

        teams = {"Bright red","Bright blue"}
        num = 1

        for i,v in pairs(players) do
            v.TeamColor = BrickColor.new(teams[num])
            num = num + 1
            if num > #teams then
                num = 1
            end
        end


---------------------------------
-- Teleport players to the map --
---------------------------------

        bspawn = mapChosenClone.BlueSpawn
        rspawn = mapChosenClone.RedSpawn

        for i,v in pairs(game.Players:GetPlayers()) do 
            name = v.Name
            check = game.Workspace:FindFirstChild(name)
            if v.TeamColor == BrickColor.new("Bright red") then
                if check then
                    checkHumanoid = check:FindFirstChild("Humanoid")
                    if checkHumanoid then
                        local distance = math.random(-4, 4);
                        check:MoveTo(rspawn.Position + Vector3.new(distance, distance, distance))
                    end
                end
            elseif v.TeamColor == BrickColor.new("Bright blue") then
                if check then
                    checkHumanoid = check:FindFirstChild("Humanoid")
                    if checkHumanoid then
                        local distance = math.random(-4, 4);
                        check:MoveTo(bspawn.Position + Vector3.new(distance, distance, distance))
                    end
                end
            end
        end


---------------------------
-- Round begins countdown --
---------------------------
       M("Game begins in 3", 1 , true)
       M("Game begins in 2", 1 , true)
       M("Game begins in 1", 1 , false)


-------------------------------
-- Countdown till round ends --
-------------------------------
local timetocountdown = 30
repeat
        M( "Time left: " ..timetocountdown, 1, true)
timetocountdown = timetocountdown - 1
                      until timetocountdown <= 0
        end
        M("The round has ended",1,false)


------------------------------------        
-- Teleport players back to lobby --
------------------------------------

        for i,v in pairs(game.Players:GetPlayers()) do
            v.Character:MoveTo(Vector3.new(108, 11.19, -29))
        end
        wait(1) --- for this i would do 
--[[ for i,v in pairs(game.Players:GetChildren()) do
v:LoadCharacter()
end
]]

---------------------
-- Destroy the map --
---------------------

        mapChosenClone:Destroy()

--------------------------------------------------
-- Needs to be 1 more player for round to begin --
--------------------------------------------------

    else
       M("You need 1 more player to join",1,true)
    end

end

Hope this was helpful. :P

0
so this will fix it? NinjoOnline 1146 — 10y
0
dosent work, the else on line 128 is red underlined NinjoOnline 1146 — 10y
0
Next time check to make sure NinjoOnline 1146 — 10y

Answer this question