After the player clicks the button, joins the team and dies; I want the GUI to be completely removed from his StarterGUI. I want it to not show up again. What is the easiest solution?
Respectfully,
player = script.Parent.Parent.Parent.Parent team = game.Teams["airman"] function onButtonClicked() player.Character.Humanoid.Health = 0 player.TeamColor = team.TeamColor script.Parent.Parent:Remove() end script.Parent.MouseButton1Down:connect(onButtonClicked)
Any easy solution for this is to insert a value into the player upon clicking.
You can then check for this value. If it exists, destroy the Gui object.
local player = game.Players.LocalPlayer --Easy way to reference the client local team = game.Teams["airman"] if player:FindFirstChild("HasSelectedTeam") then --Check for the val script.Parent.Parent:Destroy(); end function onButtonClicked() player.Character:BreakJoints() --Easy way to kill people player.Team = team --'Team' is now a property of players :) Instance.new("BoolValue",player).Name = "HasSelectedTeam"; --Insert val script.Parent.Parent:Destroy() --'Remove' is deprecated end script.Parent.MouseButton1Down:connect(onButtonClicked)
You may also simply clone the gui into the Player's PlayerGui when they join the game, using a PlayerAdded
event. With this option you can keep your code the same.
Script in serverscriptstorage
local ui = game.ReplicatedStorage.YourGui --This is the gui to be cloned game.Players.PlayerAdded:connect(function(plr) local plrui = plr:WaitForChild("PlayerGui"); ui:Clone().Parent = plrui; end)
I'd say the second solution is better, so then you don't constantly have a useless gui in your PlayerGui after that first click.
Hope I helped! And happy developing :)