I'm trying to make a basic card game and want the cards to change position depending on how many cards there are like this: https://gyazo.com/a249f906ce3c77364101551f9a3113a4
In the gif whenever the user places a card somewhere else, the other cards they're holding move through the x axis to be symmetrical.
Right now my game draws 5 cards but when 1 card leaves the rest of the cards stay in their place. https://gyazo.com/98907c6df40faebdb5dae226339cbeb9
function FindChildren(Object) local c = game.Players.LocalPlayer.Backpack.Hand -- Counts how many cards in hand for i,v in pairs(Object:GetChildren()) do if v:IsA("Frame") and v.Name == "Card" and c.Value < 5 then -- Finds frame named card local d = 0.425 + (c.Value * 0.064) -- d is the distance between each card drawn c.Value = c.Value + 1 -- counts the card in a number value wait() v:TweenPosition(UDim2.new(d, 0, 0.822, 0), "Out", "Quint", 1.5, true) wait(0.5) end FindChildren(v) end end
Any tips on what I could do to center the cards depending on the value in game.Players.LocalPlayer.Backpack.Hand ?
1) Have the cards inside a frame that is the size of the cards after they're layed out.
So the frames x size is of the num_of_cards * offset of each card * card's x size with the y being the cards y size.
2) position the frame in the center by making it's x position .5 - frame x size pretty sure.
Don't quote me on the exact numbers but that's how I think it could be done.
There's probably a way to get the offset without the for loop, but this works for now: It finds out where the last card should be without any centering, then it takes the distance away from the right edge, divides that by two to make the space on each edge even and subtracts half the size of the card to account for the card size.
template = script.Parent.cardTemplate numCards = 5 offset = .01 totalXPos = 0 --determine the initial card's offset for centering in the cards middle for i = 1, numCards do --looking at the last card, get it's position away from the right if(i == numCards)then totalXPos =((1-totalXPos)/2) - (template.Size.X.Scale/2) else totalXPos = totalXPos + template.Size.X.Scale + offset end end --create cards normally with initial card offset for i = 1, numCards do clone = template:Clone() clone.Parent = script.Parent.Cards clone.Position = UDim2.new(totalXPos,0,0,0) totalXPos = totalXPos + clone.Size.X.Scale + offset end template.Visible = false