So this is my script so basically like, erer is only true if v, which is a viewportframe that is suppose to have a number as the name, doesnt match any ge, which are boolvalues with number names inside game.Players.LocalPlayer.Floors:GetChildren().
So basically like, it is suppose to make it so that it only adds viewportframes inside the scrolling frame if there isnt the same one in the scrolling frame, but my script doesnt work in the matter that it ignores if a viewportframe is already in a scrolling frame and keeps adding it like its not there
Heres a fun little animation I made to represent it.
What I get:
Ples someone help me pls,
I don’t understand your question
I said its not an array its a TABLE. table.find only works on arrays
Like I have an idea that is to do another for i,v in pairs in the thing and add the contents into a dagtjndbkijnasjreeeeeeeeeee
so like what im tryna do is like to make it so that it only inserts the viewportframe if there isnt any viewportframes that have the same name of the viewportframe thats supposed to be teh viewportframes name
its rlly hard to explain and i dot have the time to do it rn cos i gotta go in like 30 minutes
ok so what do i finhd with table.find cos its an array of objects and i need to specifically find the name
the name of the object that is
Can someone help me pleas i ony have 20 minutes left please sonenone help it isnt this hard
Your code is very difficult to follow with your variable names. Choosing better variable names would make this code much cleaner.
Your problem is that you are checking
v.Name ~= ge.Name, when it should be
You should then later check that
ere == false.
Here is some better code that uses good variable naming conventions to make your code easier to read.
local player = game:GetService("Players").LocalPlayer local floors = player.Floors while wait(5) do for _, floor in ipairs(floors:GetChildren()) do local hasViewportFrame = false for _, frame in ipairs(script.Parent.ImageLabel.ScrollingFrame:GetChildren()) do if frame:IsA("ViewportFrame") and frame.Name == floor.Name then hasViewportFrame = true end end if not hasViewportFrame then -- make your viewport end end end
A big concern I have with your current code is it’s on a loop every 5 seconds. Why is this? If you want to listen to floors being created/destroyed, you should use the appropriate API for that (ChildAdded/ChildRemoved)
You could use a generic for and iterate through the array, and use
rawequal to check if they’re the same. For example
local IsInArray = false for _, Object in ipairs(Objects) do if rawequal(Object, Compare) then IsInArray = true break end end
I hope this helped.
That would be what you’d compare
Object to. I probably could’ve come up with a better name lol.
This is what I did and now it doesnt insert the viewportframe in the scrollingframes at all?
while wait(5) do for i,v in pairs(game.Players.LocalPlayer.Floors:GetChildren()) do local erer = false for er,ge in pairs(script.Parent.ImageLabel.ScrollingFrame:GetChildren()) do if ge:IsA("ViewportFrame") then if v.Name==ge.Name then erer = true end end end if erer == false then
What is “compare”?,