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.
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.