Added Child not being recognized as variable

  1. I am trying to clone a part into the workspace and then tweening all the parts

  2. It is cloning but is not tweening

local Workspace = game:GetService("Workspace")
local RepStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local warpPart = RepStorage.CircleMeshWarp

while true do
	task.wait(2)
	local warpClone = warpPart:Clone()
	warpClone.Mesh.Scale =  Vector3.new(2, 0.01, 2)
	warpClone.Parent = Workspace
end

Workspace.ChildAdded:Connect(function(child)
	if child.Name == "CircleMeshWarp" then
		local mesh = child:FindFirstChild("Mesh")
		if mesh then
			local TweenData = TweenInfo.new(3, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
			local Tween = TweenService:Create(mesh, TweenData, {Scale = Vector3.new(10, 0.01, 10)})
			Tween:Play()
		else print("Didn't Work!!")
		end
	end
end)
1 Like

Any code that comes after a while loop doesn’t run. Put the workspace.ChildAdded function before the while loop, and then run the script again.

2 Likes

Is there a way to do a while true loop above the code or will it work fine being at the end of the code

1 Like

I believe the while loop should still run at the end of the code.

1 Like

Wrap your code in a thread and it should run well while being above the event. The reason it doesn’t work the way you did it is that when something got added the event wasn’t set so it missed it. Using a thread makes the code run side by side with the one you’re currently running
Ex:

task.spawn(function()
	while true do
		task.wait(2)
		local warpClone = warpPart:Clone()
		warpClone.Mesh.Scale =  Vector3.new(2, 0.01, 2)
		warpClone.Parent = Workspace
	end
end)
1 Like