(sorry for the title, but lol) Alright, i'm making an explorer for a script builder for training purposes. Everything's working well, BUT... I'm trying to make a search function which haves to search for objects. (duh) It does it job well, but makes like kinda "gaps" which i didn't want to appear. I can't explain it but try trying out the explorer and try to search something which appears at the top of the explorer, then something at the bottom of the explorer, you will notice that in the second search the object will need to be scrolled down to.
Very hard to explain, but..
Here's the code: (localscript) [the line i think is not working propellery is 83]
-- variables local me = game.Players.LocalPlayer -- Create ScreenGui local screenGui = Instance.new("ScreenGui") screenGui.Parent = me.PlayerGui -- Create ScrollingFrame local scrollingFrame = Instance.new("ScrollingFrame") scrollingFrame.Position = UDim2.new(0.2, 0, 0.1, 0) scrollingFrame.Size = UDim2.new(0, 200, 0, 300) scrollingFrame.CanvasSize = UDim2.new(0, 200, 2, 0) scrollingFrame.BackgroundColor3 = BrickColor.Blue().Color scrollingFrame.Parent = screenGui scrollingFrame.ScrollingEnabled = true scrollingFrame.Active = true scrollingFrame.Draggable = true scrollingFrame.ScrollBarThickness = 12 -- Create SearchBar local s = Instance.new("TextBox", scrollingFrame) s.BackgroundColor3 = BrickColor.White().Color s.TextColor3 = BrickColor.Black().Color s.Size = UDim2.new(0,125, 0,50) s.Text = "Search" s.TextScaled = true s.Position = UDim2.new(0,0, 0,0) function refresh(word) if word then for i,v in pairs(scrollingFrame:GetChildren()) do if v.Name == "Object" then v:Destroy() end end local i = 0 for i,v in pairs(workspace:GetChildren()) do if string.lower(v.Name):match(word) then local txtbutton = Instance.new("TextButton", scrollingFrame) txtbutton.Position = UDim2.new(0,0, 0,50 * i) txtbutton.Text = v.Name txtbutton.Name = "Object" txtbutton.Size = UDim2.new(0,200, 0,50) txtbutton.MouseButton1Down:connect(function() local frame = Instance.new("Frame", screenGui) frame.Active = true frame.Draggable = true frame.BackgroundColor3 = BrickColor.Blue().Color frame.Position = UDim2.new(0,500, 0,100) frame.Size = UDim2.new(0,250, 0, 250) local n = Instance.new("TextButton", frame) n.BackgroundTransparency = 1 n.TextColor3 = BrickColor.White().Color n.Size = UDim2.new(0,125, 0,25) n.Text = v.Name n.TextScaled = true n.Position = UDim2.new(0,62.5, 0,0) local x = Instance.new("TextButton", frame) x.BackgroundColor3 = BrickColor.Red().Color x.TextColor3 = BrickColor.White().Color x.Size = UDim2.new(0,25, 0,25) x.Text = "X" x.TextScaled = true x.Position = UDim2.new(0,225, 0,0) x.MouseButton1Down:connect(function() frame:Destroy() end) local rb = Instance.new("TextButton", frame) rb.BackgroundColor3 = BrickColor.Black().Color rb.TextColor3 = BrickColor.White().Color rb.Size = UDim2.new(0,100, 0,50) rb.Text = "Destroy()" rb.TextScaled = true rb.Position = UDim2.new(0,75, 0,150) rb.MouseButton1Down:connect(function() v:Destroy() frame:Destroy() refresh() end) end) if string.lower(v.Name):match(word) then local i = i + 1 end -- even if the name dosen't match word IT STILL ADDS 1 POINT TO THE I VARIABLE??? else end scrollingFrame.CanvasSize = UDim2.new(0, 200, 2, 0) + UDim2.new(0,0, 0,50 * i) end else for i,v in pairs(scrollingFrame:GetChildren()) do if v.Name == "Object" then v:Destroy() end end local i = 0 for i,v in pairs(workspace:GetChildren()) do local txtbutton = Instance.new("TextButton", scrollingFrame) txtbutton.Position = UDim2.new(0,0, 0,50 * i) txtbutton.Text = v.Name txtbutton.Name = "Object" local i = i + 1 txtbutton.Size = UDim2.new(0,200, 0,50) txtbutton.MouseButton1Down:connect(function() local frame = Instance.new("Frame", screenGui) frame.Active = true frame.Draggable = true frame.BackgroundColor3 = BrickColor.Blue().Color frame.Position = UDim2.new(0,500, 0,100) frame.Size = UDim2.new(0,250, 0, 250) local n = Instance.new("TextButton", frame) n.BackgroundTransparency = 1 n.TextColor3 = BrickColor.White().Color n.Size = UDim2.new(0,125, 0,25) n.Text = v.Name n.TextScaled = true n.Position = UDim2.new(0,62.5, 0,0) local x = Instance.new("TextButton", frame) x.BackgroundColor3 = BrickColor.Red().Color x.TextColor3 = BrickColor.White().Color x.Size = UDim2.new(0,25, 0,25) x.Text = "X" x.TextScaled = true x.Position = UDim2.new(0,225, 0,0) x.MouseButton1Down:connect(function() frame:Destroy() end) local rb = Instance.new("TextButton", frame) rb.BackgroundColor3 = BrickColor.Black().Color rb.TextColor3 = BrickColor.White().Color rb.Size = UDim2.new(0,100, 0,50) rb.Text = "Destroy()" rb.TextScaled = true rb.Position = UDim2.new(0,75, 0,150) rb.MouseButton1Down:connect(function() v:Destroy() frame:Destroy() refresh() end) end) end scrollingFrame.CanvasSize = UDim2.new(0, 200, 2, 0) + UDim2.new(0,0, 0,50 * i) end end refresh() local g = Instance.new("TextButton", scrollingFrame) g.BackgroundColor3 = BrickColor.Green().Color g.TextColor3 = BrickColor.White().Color g.Size = UDim2.new(0,50, 0,50) g.Text = "Go!" g.TextScaled = true g.Position = UDim2.new(0,125, 0,0) g.MouseButton1Down:connect(function() refresh(s.Text) end) me.Chatted:connect(function(msg) if string.lower(msg) == "refresh" or string.lower(msg) == "ref" then refresh() end end)
On line 83, take off "local", because I think that ends up keeping that value local to the if then block and not touching the value you initialized at line 93.
In line 36, change the i to something else like ii,v. Once you use a variable in a for loop, you should never touch it. have your code in the loop within the IF then block,cheking for the match, instead - that might help. If you do this you probably don't need line 83.