local findgear = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool")
if findgear and findgear:FindFirstChild("BoostName") then
GL[findgear.Name] = true
script.Parent.BoostItemsUsedText.Visible = true
if table.find(u13,findgear.Name) then
addItem(findgear.Name)
end
end
local Parent = script.Parent
local BoostItemsList = Parent:WaitForChild("BoostItemsList") -- has a ui list layout
function addItem(what)
Parent.BoostItemsUsedText.Visible = true;
local Sample = BoostItemsList.Sample:Clone();
table.insert(tab, Sample);
Sample.Text = what;
if what == "Vertical Mobility" then
Sample.LayoutOrder = 0;
Sample.TextColor3 = Color3.new(1,1,0);
end;
Sample.Parent = BoostItemsList
end;
This code runs perfectly fine, but the problem is:
If you hover over it again, it’ll make another textlabel EVEN though it already set the text label, is there a way i can make it only happen once?
only once? , create a BoolValue, and set it to false, when you change the TextLabel
Set it to TRUE
and
I believe the issue is here?
local AlreadyChangedTextLabel = false -- BoolValue
function addItem(what)
if AlreadyChangedTextLabel == true then
--this will prevent from changing it again or creating multiplications
return
end
AlreadyChangedTextLabel = true -- Setting to True, and will run only once
Parent.BoostItemsUsedText.Visible = true;
local Sample = BoostItemsList.Sample:Clone();
table.insert(tab, Sample);
Sample.Text = what;
if what == "Vertical Mobility" then
Sample.LayoutOrder = 0;
Sample.TextColor3 = Color3.new(1,1,0);
end;
Sample.Parent = BoostItemsList
end;
You can just return the function if the ‘Sample’ object already exists.
function addItem(what)
if (BoostItemsList:FindFirstChild("Sample")) then
return -- You can also destroy this if you want it to replace
end
Parent.BoostItemsUsedText.Visible = true;
local Sample = BoostItemsList.Sample:Clone();
table.insert(tab, Sample);
Sample.Text = what;
if what == "Vertical Mobility" then
Sample.LayoutOrder = 0;
Sample.TextColor3 = Color3.new(1,1,0);
end;
Sample.Parent = BoostItemsList
end;
Please mark this as solution if this helps with your problem !