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

GUIs not replicating to PlayerGui but staying in StarterGui?

Asked by 8 years ago

I've been experiencing an issue with my game's GUIs. The GUIs do not replicate themselves to the player's PlayerGui, and the properties change in StarterGui instead of PlayerGui. I am using a normal script to control each GUI.

The Output gave me no errors.

Mainbar = game.StarterGui.Mainbar
---------------
MainbarFrame = Mainbar.MainbarFrame
---------------
MainbarText = MainbarFrame.MainbarText
---------------
LobbyMusic = game.workspace.LobbyMusic

---------------------------------------
--||MAIN FUNCTIONS||--
---------------------------------------
while true do wait(1)

wait(2)

LobbyMusic:Play()

for i = 1,25 do
    LobbyMusic.Volume = i*0.04
    wait()
end

MainbarText.Text = "Get ready for the next round!"

wait(2)

for i = 5,0,-1 do
MainbarText.Text = "Next round starting in: " .. i .. " seconds"
wait(1)

if i == 0 then
MainbarFrame.Visible = false
    end
end

--Fade the LobbyMusic out
for i = 1,100 do
    LobbyMusic.Volume = 1-i*0.01
    wait()
end

2 answers

Log in to vote
2
Answered by 8 years ago

You have two errors in your script. One is that you forgot an end, and two is you didn't define the playergui. You can't just change the text in startergui you have to change the text in the playergui. So you have to define all the players in the game than get all of their playerguis. Like this:

for _, player in ipairs(game.Players:GetChildren()) do -- this gets all the players in the game and defines all of them as player!
    --code
end

This should be your whole script:

Mainbar = game.StarterGui.Mainbar
---------------
MainbarFrame = Mainbar.MainbarFrame
---------------
MainbarText = MainbarFrame.MainbarText
---------------
LobbyMusic = game.workspace.LobbyMusic

---------------------------------------
--||MAIN FUNCTIONS||--
---------------------------------------
Mainbar = game.StarterGui.Mainbar
---------------
MainbarFrame = Mainbar.MainbarFrame
---------------
MainbarText = MainbarFrame.MainbarText
---------------
LobbyMusic = game.workspace.LobbyMusic

---------------------------------------
--||MAIN FUNCTIONS||--
---------------------------------------
while true do wait(1)

wait(2)

LobbyMusic:Play()

for i = 1,25 do
    LobbyMusic.Volume = i*0.04
    wait()
end
for _, player in ipairs(game.Players:GetChildren()) do
    player.PlayerGui.Mainbar.MainbarFrame.MainbarText.Text = "Get ready for the next round!"
    wait(2)
    for i = 5,0,-1 do
    player.PlayerGui.Mainbar.MainbarFrame.MainbarText.Text = "Next round starting in: " .. i .. " seconds"
    wait(1)
    if i == 0 then
MainbarFrame.Visible = false
    end
end

--Fade the LobbyMusic out
for i = 1,100 do
    LobbyMusic.Volume = 1-i*0.01
    wait()
    end
end
end
Ad
Log in to vote
0
Answered by 8 years ago

The StarterGui does not actively update GUIs in other players' PlayerGui. All it does is clone its contents into their PlayerGui each time they spawn. If you want the PlayerGuis to be updated, you'll have to loop through each player's PlayerGui and modify them manually.

If not using FilteringEnabled, you can directly read and and change the values of GUIs in the PlayerGui, and can use that same script you're using now if you replace each line that changes the StarterGui to a loop that changes the GUI in every player's PlayerGui.

If using FilteringEnabled, a regular script won't be able to see or modify what's in a player's PlayerGui and you'll have to use RemoteEvents/RemoteFunctions to communicate these values to the player and have them update their own GUI with a local script.

Answer this question