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

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

Asked by 7 years ago
Edited by OldPalHappy 7 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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

0
Thank you so much. MaculusTheGreat 10 — 7y
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. Goulstem 8144 — 7y
Ad

Answer this question