Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Positions every frame at the same position?

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

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.