so i have to get the “buy” button in my frames, how do i do that?
script below only takes the FRAMES, not THEIR CHILDREN
i wanted to do ScrollingFrame.Invicibility:GetChildren(), ScrollingFrame.[“High Speed”]:GetChildren(), etc. at first, but it didnt work
for _,mutatorBtn in pairs(script.Parent.ScrollingFrame:GetChildren()) do -- struggling on this one help lol
if not mutatorBtn:IsA("TextButton") then continue end
mutatorBtn.MouseButton1Click:Connect(function()
if Player.leaderstats.Coins.Value < (tonumber(mutatorBtn.Price.Value)) then return end
mutatorEvent:FireServer({Name = mutatorBtn.Name, Price = tonumber(mutatorBtn.Price.Value)})
end)
end
You can have a for loop inside a foor loop like this:
for _, child in pairs(something:GetChildren()) do
for _, childOfChild in pairs(child:GetChildren()) do
--This will loop through every child of every child of "something"
end
end
end
Assuming each instance has the same structure (each child is a Frame which has a child called ‘Buy’ which is a TextButton), it would be best to directly get this Instance, as opposed to loop to find it.
for _, frame in pairs(<ScrollingFrame>:GetChildren()) do
if frame:IsA('Frame') and frame:FindFirstChild('Buy') then
-- Connect your MouseButton1Click signal here and the remaining code
end
end
local tagName = "buyingButtons"
local CollectionService = game:GetService("CollectionService")
local Player = game:GetService("Players").LocalPlayer
local mutatorEvent = nil -- where your event is
-- Reducing if statements is unnecessary
CollectionService:GetInstanceAddedSignal(tagName):Connect(function(button)
button.Activated:Connect(function()
if Player.leaderstats.Coins.Value >= (tonumber(button.Price.Value)) then
mutatorEvent:FireServer {
Name = button.Name,
Price = tonumber(button.Price.Value)
}
else
print("not enough coins")
end
end)
end)
for _,mutatorBtn in ipairs(script.Parent.ScrollingFrame:GetDescendants()) do
if not mutatorBtn:IsA("TextButton") then
CollectionService:AddTag(mutatorBtn, tagName)
end
end
Your mutatorBtn is the Buy we get from the Frame, so you’d either just make local mutatorBtn = frame.Buy or you can switch out mutatorBtn to frame.Buy.