What do you want to achieve? I want to move cards with moving part
I made card spawn function to spawn cards and then weld them to the moving part
local function createCards(value)
local cardHeight = 0.11
for i = 1, value do
local newUnknownCard = RS.Card:Clone()
newUnknownCard.Parent = workspace.UnknownCards
newUnknownCard.ClickablePart.CFrame = CFrame.new(
workspace.Map.Platform.CFrame.X,
workspace.Map.Platform.CFrame.Y + ((i - 1) * cardHeight) + 0.19,
workspace.Map.Platform.CFrame.Z
) * CFrame.Angles(0, math.rad(-90), 0)
end
for i, part in pairs(workspace.UnknownCards:GetChildren()) do
local weld = Instance.new("Weld")
weld.Part0 = workspace.Map.Platform
weld.Part1 = part.ClickablePart
weld.Parent = workspace.Map.Platform
end
end
After that, I have a code literally in 1 line that just moves the part using tweenservice
local TweenService = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")
local function createCards(value)
local cardHeight = 0.11
for i = 1, value do
local newUnknownCard = RS.Card:Clone()
newUnknownCard.Parent = workspace.UnknownCards
newUnknownCard.ClickablePart.CFrame = CFrame.new(
workspace.Map.Platform.Position.X,
workspace.Map.Platform.Position.Y + ((i - 1) * cardHeight) + 0.19,
workspace.Map.Platform.Position.Z
) * CFrame.Angles(0, math.rad(-90), 0)
-- Create a weld for each card
local weld = Instance.new("Weld")
weld.Part0 = workspace.Map.Platform
weld.Part1 = newUnknownCard.ClickablePart
weld.C0 = weld.Part0.CFrame:inverse() * weld.Part1.CFrame -- Set the relative position
weld.Parent = newUnknownCard.ClickablePart -- Parent the weld to the card
end
end
-- Example Tween to move the platform
local function movePlatform()
local platform = workspace.Map.Platform
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local goal = {Position = platform.Position + Vector3.new(0, 0, 10)} -- Adjust the goal position as needed
local tween = TweenService:Create(platform, tweenInfo, goal)
tween:Play()
end
-- Usage
createCards(5) -- Create 5 cards
movePlatform() -- Move the platform