Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Deleting a GUI after respawn? (one-time GUI)

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

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)

1 answer

###Solution 1

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)

###Solution 2

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.

  • Note - place your gui in ReplicatedStorage, and reference it from the script.

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)

###Which one is best?

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 :)

2 comments

0

Thank you so much.

0

No problem :) Remember to accept my answer if it helped you. It ensures both the asker and the answerer get the reputation they deserve.

This discussion is preserved as it was. New answers, comments, and votes are closed.