I’m trying to make a plugin that when you select a TextButton, it puts a UICorner in it. To check if the player has selected the TextButton, I’m running a while wait() do (which is probably not the best of things to do, so please help me find a different way).
Since it’s just a continious loop of seeing if the player has selected the button, when they do, it spawn lots and lots of UICorner's in it because of the loop.
How do I make my script know that there is already a child that is a UICorner so it doesn’t spawn more in?
Script:
while wait() do
for _, object in pairs(Selection:Get()) do
if object:IsA("TextButton") then
local Corner = Instance.new("UICorner")
Corner.Parent = object
Corner.CornerRadius = UDim.new(0.2,0)
end
end
end
Selection.SelectionChanged:Connect(function()
for _, object in pairs(Selection:Get()) do
if object:IsA("TextButton") then
local Corner = Instance.new("UICorner")
Corner.Parent = object
Corner.CornerRadius = UDim.new(0.2,0)
end
end
end)
local Selection = game:GetService("Selection")
Selection.SelectionChanged:Connect(function()
for _, Object in pairs(Selection:Get()) do
if Object:IsA("TextButton") then
if not Object:FindFirstAncestorWhichIsA("UICorner") then
local Corner = Instance.new("UICorner")
Corner.Parent = Object
Corner.CornerRadius = UDim.new(0.2,0)
end
end
end
end)
local Selection = game:GetService("Selection")
Selection.SelectionChanged:Connect(function()
for _, Object in pairs(Selection:Get()) do
if Object:IsA("TextButton") then
if not Object:FindFirstChildWhichIsA("UICorner") then
local Corner = Instance.new("UICorner")
Corner.Parent = Object
Corner.CornerRadius = UDim.new(0.2,0)
end
end
end
end)
I’m really confused where to put this. I’ve tried multiple times.
It now only says Select a GUI Object (0).
local Selection = game:GetService("Selection")
Selection.SelectionChanged:Connect(function()
for _, Object in pairs(Selection:Get()) do
if Object:IsA("TextButton") then
if not Object:FindFirstChildWhichIsA("UICorner") then
for i, v in pairs(Selection:Get()) do
if not v:IsA("GuiObject") then
Selection:Get()[i] = nil
script.Parent.Subtitle.Text = "Select a GUI Object ("..i..")"
end
end
local Corner = Instance.new("UICorner")
Corner.Parent = Object
Corner.CornerRadius = UDim.new(0.2,0)
end
else
script.Parent.Subtitle.Text = "Select a GUI Object (0)"
end
end
end)
Make sure that when you remove the item, you are removing it from a variable, not from Selection:Get()
Change this:
for i, v in pairs(Selection:Get()) do
...
Selection:Get()[i] = nil
.... -- other stuff here
end
To this:
local sel = Selection:Get()
for i, v in pairs(sel) do
...
sel[i] = nil
.... -- other stuff here
end
script.Parent.Subtitle.Text = "Select a GUI Object ("..#sel..")"
Sorry if this is annoying btw, I’m new to plugins!
local Selection = game:GetService("Selection")
Selection.SelectionChanged:Connect(function()
for _, Object in pairs(Selection:Get()) do
if Object:IsA("TextButton") then
if not Object:FindFirstChildWhichIsA("UICorner") then
local Corner = Instance.new("UICorner")
Corner.Parent = Object
Corner.CornerRadius = UDim.new(0.2,0)
end
else
script.Parent.Subtitle.Text = "Select a GUI Object (0)"
end
end
local Sel = Selection:Get()
for i, v in pairs(Sel) do
if not v:IsA("GuiObject") then
Sel[i] = nil
script.Parent.Subtitle.Text = "Select a GUI Object ("..i..")"
end
end
end)