Remote.OnClientEvent:Connect(function()
local groups = {script.Parent.Frame:FindFirstChild("Things"), script.Parent.Frame:FindFirstChild("Things2")}
for _, i in ipairs(groups) do
for _, e in pairs(i:GetDescendants()) do
for _, d in pairs(plrresearch:GetChildren()) do
local NAMES = d
local TroopsVALUE = d.Value
if e.Name == NAMES.Name then if e:IsA("ViewportFrame") then
for _, q in pairs(e:FindFirstChild("BUY")) do -- HERE THERE IS A INVALID ARGUMENT ERROR
if q:IsA("TextButton") then
--something happens idk
print("Something, Idk yet")
end
end
end
end
end
end
end
end)
Here is a more organized version :
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("remote")
remote.OnClientEvent:Connect(function()
local groups = {
script.Parent.Frame:FindFirstChild("Things"),
script.Parent.Frame:FindFirstChild("Things2")
}
for _, i in ipairs(groups) do
for _, e in pairs(i:GetDescendants()) do
for _, d in pairs(plrresearch:GetChildren()) do
local NAMES = d
local TroopsVALUE = d.Value
if e.Name == NAMES.Name then if e:IsA("ViewportFrame") then
for _, q in pairs(e:FindFirstChild("BUY")) do -- HERE THERE IS A INVALID ARGUMENT ERROR
if q:IsA("TextButton") then
print("Something, Idk yet")
end
end
end
end
end
end
end
end)
What is plrresearch
?
What are the groups? What are you trying to make? Any errors in the output? What did the code do when you ran it? Please provide more info.
Clearing Up a bit.
I am trying to learn to make a thing where there is a Gui that will have the price of the item depending on what level item does the player own. There are multiple of these Items and there are Viewport frames named after them and the Player.Research has the Values / levels of the items.
(prices of things are on a module script that is basically just the same that I have for the server side , but just in replicated storage so its local, bc I donât really care if they change the price on their screen, the module on server side is used for other things that require buying things , but thats besides the point)
I am currenctly trying to make it in a way that when the gui opens it detects what levels the things are and it puts the right prices.
I am currently stuck in that part of the script. I wish that I would find the most efficent method for this action.
Local player = game.Players.LocalPlayer
Local plrresearch = player.Research --(Folder containing Number Values)
It is expecting a table at
"invalid argument #1 to âpairsâ (table expected, got nil)
did you forget :getchildren() ?
the error says it all
Where Did I forget :GetChildren
?
I donât see where I should have another one?
since you used findfirstchild BUY is an instance
you cant loop over an instance it dont make sense
i just quoted his original post and organized it.
i know theres still wrong code in there you cant loop over an instance it has to be a table
show us the explorer tab of the gui if u still hadnt solved it
Location of the GUI
is BUY the button youre to get or is there text buttons inside of it?
, âBUYâ Is the one I am trying to Get
yea i dont think i can help u fix your script, its too messy and doesnt make sense
if you want to detect click on the button just add a localscript to it and use mousebutton1click
I donât really understand the meaning of the loop here. BUY
is a TextButton, a singular instance, thereâs nothing you can loop through in it. If you wanted to check if the BUY
exists, you can just do this:
local buyButton = e:FindFirstChild("BUY") -- this returns nil if the instance doesn't exist
if buyButton then
-- if the buyButton is NOT nil, then ... your code
else
Yeah I know right, Btw this had nothing to do with clicking the button