I’m trying to make some blocks move so the player can dodge them while standing on platforms:
-- This block of code clones one of the blocks that is supposed to move,
-- and clones the "BlockMover" script into the cloned part. I think it works correctly.
blockOne = game.Workspace.Blocks.Block1
blockTwo = game.Workspace.Blocks.Block2
blockThree = game.Workspace.Blocks.Block3
blockFour = game.Workspace.Blocks.Block4
local function cloneBlock(block)
local clonedBlock = block:Clone()
local clonedMoverScript = game.ServerScriptService.BlockController.BlockMover:Clone()
clonedBlock.Parent = game.Workspace.Blocks.ClonedBlocks
clonedMoverScript.Parent = clonedBlock
end
-- For quick testing:
wait(5)
cloneBlock(blockOne)
The “BlockMover” script is shown below:
-- This should run when the script is cloned into a block, since its parent is changed.
-- Doesn't print the line out...
script.Parent.AncestryChanged:Connect(function(_, parent)
print("Ancestry Change Detected")
local TweenService = game:GetService("TweenService")
local block = script.Parent
local Info = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1, false, 0)
local Goals = {Position = Vector3.new(78, 6.5, -12)}
local moveForwards = TweenService:Create(block, Info, Goals)
moveForwards:Play()
end)
The first script works correctly, and clones the block and scripts into the correct places. The second script does not print the text at all.
Does anyone know why AncestryChanged isn’t firing? And could I be doing this way more efficiently?
Thanks.