###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
local team = game.Teams["airman"]
if player:FindFirstChild("HasSelectedTeam") then
script.Parent.Parent:Destroy();
end
function onButtonClicked()
player.Character:BreakJoints()
player.Team = team
Instance.new("BoolValue",player).Name = "HasSelectedTeam";
script.Parent.Parent:Destroy()
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
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
Thank you so much.
No problem :) Remember to accept my answer if it helped you. It ensures both the asker and the answerer get the reputation they deserve.