Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this position them all at the same position?

Asked by 8 years ago

I am trying to make this clone a frame, and position them 75 studs(or whatever the term is for GUI's) away from each-other, but this position's them all at the same position, can anyone tell me how to fix this problem?

Code:

for i,v in pairs(game.ReplicatedStorage.TestingFolder:GetChildren()) do
    local count = 0
    local notification = script.Notification:Clone()
    notification.Parent = script.Parent
    count = count + 1   
    notification.Position = UDim2.new(0,0,0,75*count)
end
0
Swap lines 1 and 2 and it will work perfectly fine. Discern 1007 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Think about how you set up the script. for i,v in pairs(game.ReplicatedStorage.TestingFolder:GetChildren()) do repeats all the code in it each time. So, looking through this, I noticed that each time, it sets "count" back to zero. Lets say you iterated through the loop 3 times, the value of count each time would be set to zero, and then added 1 to it. (set to zero then add 1, reset to zero then add 1, reset to zero then add one) So how do you fix this? Easy, just define count before you start the loop, like below.

local count = 0

for i,v in pairs(game.ReplicatedStorage.TestingFolder:GetChildren()) do
    local notification = script.Notification:Clone()
    notification.Parent = script.Parent
    count = count + 1   
    notification.Position = UDim2.new(0,0,0,75*count)
end

Ad

Answer this question