I am trying to make a SurfaceGui ScrollingFrame shop but I don't want to duplicate the frame and edit the text, etc for each item. This script work's some what I just can't figure out how to make it position every frame 31 studs(or whatever the GUI Position is measured in) away from eachother. Can anyone help me?
gather = game.ServerStorage.GearStorage:GetChildren() scroll = script.Parent.ScrollingFrame for _,v in pairs(gather) do local frame = script.Template:Clone() frame.Name = v.Value frame.Parent = scroll frame.Position = frame.Position + UDim2.new(0,0,0,31) frame.ItemName.Text = v.Value.." | "..v.Price.Value end
The Pairs
iterator function returns two values, the index number, and the index value. You should define 'i' as the index number rather than '_'. Additionally, you should use ipairs
because ipairs goes in order and pairs doesn't.
Why i'm telling you this is because you can offset each gui from one another by using this i value, since it's the index number. Multiply it by whatever amount you want the guis to be away from eachother .
gather = game.ServerStorage.GearStorage:GetChildren() scroll = script.Parent.ScrollingFrame for i,v in ipairs(gather) do local frame = script.Template:Clone() frame.Name = v.Value frame.Parent = scroll frame.Position = frame.Position + UDim2.new(0,0,0,31*i) frame.ItemName.Text = v.Value.." | "..v.Price.Value end