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

How do I stop my team-only GUI from disappearing after I reset?

Asked by 4 years ago

I recently looked up how to get my 'RadioGui' to only show up on the 'Police' team. I followed a tutorial from 6 years ago, and it works perfectly fine except for one thing: my GUI disappears when I die/reset.

My script in Workspace, called 'RadioTeamScript':

game.Players.PlayerAdded:connect(function(plr)

    if plr.TeamColor == BrickColor.new("Dark blue") then

        local gui = game.ReplicatedStorage.RadioGui

        gui.Parent = plr.PlayerGui;

    end

end)

I've placed my 'RadioGui' in Replicated Storage. I need a solution so, if my character dies/resets, it will not delete the GUI - it needs to stay on the screen all the time!

I'm trying this in a test server, and also, playing in a real multiplayer server does not work. It appears for the 'Police' team only and not the 'Civilian' team, as intended, however if I reset or die on the 'Police' team my GUI disappears never to be found again. Of course, I have tested many times and the 'RadioGui' always disappears after my death. I was thinking a loop could possibly work but 1. I do not know how to script one and 2. It may just make the radio overlap itself infinite times.

Any questions I'll be glad to respond to as I'm not a great scripter and this is my first question on the site! Thanks.

0
If my answer fixed it mark it as accepted LeHelary 142 — 3y

1 answer

Log in to vote
0
Answered by
LeHelary 142
4 years ago
Edited 4 years ago

For security reasons I highly reccomand you to use ServerStorage instead of ReplicatedStorage to store GUI's and tools. Also, the script has some errors.

gui.Parent = plr.PlayerGui;

The ";" at the end would return an error, in lua there's no line end character.

local gui = game.ReplicatedStorage.RadioGui

This way you are taking the GUI from ReplicatedStorage and then moving it in the player's PlayerGui. This means other players won't get the GUI as it's been moved from it's location. You should use ":Clone()" to create a duplicate and then give that to the player.

How do I stop my team-only GUI from disappearing after I reset?

To stop a GUI from disappearing you can set the "ResetOnSpawn" property of the GUI object to false. Or you could give the player a new GUI every time but I think there's no need for that.

So in conclusion, the fixed script is:

game.Players.PlayerAdded:connect(function(plr)

    if plr.TeamColor == BrickColor.new("Dark blue") then

        local gui = game.ReplicatedStorage.RadioGui:Clone()

        gui.Parent = plr.PlayerGui

    end

end)

Also you should change "ResetOnSpawn" property of the GUI instance, and if you can use ServerStorage instead of ReplicatedStorage to store the GUI.

Hope this helps.

0
Also, the player should SPAWN in that team to get the GUI. If you have a team changer script you should use that to give the GUI instead of PlayerAdded event LeHelary 142 — 4y
0
So, the bit you were talking about works and my GUI does not disappear now. However, as you brought up, I need to adapt it so that when you JOIN a team you get the GUI. How could I give the GUI in this instance? I can supply you with the code for the team change GUI script if needed. epicnessgamre 0 — 4y
0
Uhm sorry for responding after 23 days but it's simple really, instead of using the PlayerAdded event, you just run the script when the player changes team, in the change team GUI script LeHelary 142 — 4y
0
you just need a very basic understanding of the script you are modifying LeHelary 142 — 4y
0
or actually, I think you should use CharacterAdded LeHelary 142 — 4y
Ad

Answer this question