TweenService:Create failed because Instance is null

Hi “TweenService: Create failed because Instance is null” is error in this script, but I don’t know why.

local tweenService = game:GetService("TweenService")
local tile = script:GetChildren()
local track = workspace.trat.Track
local ties = track.Ties
local tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
--local part = script.rusen
--local vozen = script.vozen
--------------------
for i = 1, #tile do
	print(tile[i].Name)
	while true do
		for i = 1, #ties:GetChildren() do
			print(ties[i].Name)
			local tween = tweenService:Create( tile[i] , tweenInfo, {CFrame = ties[i].CFrame} )
			tween:Play()
			tween.Completed:Wait()
	end
		----------------------
	end
	end

The goal is for multiple parts to move along the route with a single script.
Tween gets stuck right at the first, but first comes to the first position where he should start.
Any ideas for a solution?

Just use pairs() loop.

local tweenService = game:GetService("TweenService")
local tile = script:GetChildren()
local track = workspace.trat.Track
local ties = track.Ties
local tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
--local part = script.rusen
--local vozen = script.vozen
--------------------
for index,single_tile in pairs(tile) do
	print(single_tile.Name)
	while true do
		for i = 1, #ties:GetChildren() do
			print(single_tile.Name)
			local tween = tweenService:Create( single_tile , tweenInfo, {CFrame = ties[i].CFrame} )
			tween:Play()
			tween.Completed:Wait()
	end
		----------------------
	end
	end

What was causing the error?

Your for i loop, because the i is a variable and its getting updated 2 times.
If you use pairs() loop in the first loop then it will fix the error

Your tile was getting this i variable
image

(Well I am not great at teaching, so sorry if you cant understand anything.)

2 Likes

ties and tiles are not the same

1 Like

Exactly, thats why when the loop was running for ties the i index
it was getting ties index instead of tiles one.

Tiles index (i) was getting replaced by the ties index (i).

You’re referencing to the ties object as if it was a table. Did you mean to write
local ties = track.Ties:GetChildren() ?

They did,
image

Where is ties assigned to be a table?

ties is initialized as an object:
image
yet OP is referencing to it as if it was a table:
image

1 Like

not this, because I have them lined up
if I gave
local ties = track.Ties: GetChildren () would go randomly
that’s why I give it

:GetChildren() returns a table of all the instances in a parent.

1 Like

Hey, can you try the code i’ve posted?

If it wont work then let me know.

ties IS NEVER ASSIGNED TO BE A TABLE, that is, INCLUDING GetChildren(), therefore cannot be referenced as if it was a table.

1 Like

otherwise I have tried it now, only one part works of the two which is weird
image

try this:

local tweenService = game:GetService("TweenService")
local tile = script:GetChildren()
local track = workspace.trat.Track
local ties = track.Ties
local tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
--local part = script.rusen
--local vozen = script.vozen
--------------------
for index,single_tile in pairs(tile) do
	print(single_tile.Name)
	while true do
		for index,tie in pairs(ties:GetChildren()) do
			print(single_tile.Name)
			local tween = tweenService:Create( single_tile , tweenInfo, {CFrame = tie.CFrame} )
			tween:Play()
			tween.Completed:Wait()
		end
		----------------------
	end
end
2 Likes

These two print statements are supposed to be different. Why did you make them exactly the same?

1 Like

Its not gonna work, and I dont recommend you to use for i = 0,10 loops
Because its confusing with variables.

As you can see,
image

it should be tile[i]
Or If you did it on purpose, then I dont think you got how loops with index works.

2 Likes

OP used the variable i twice in the orignal script. We can’t be sure which i they want to reference. That’s why I asked for more information.

Thats why i’ve used for pairs loop to fix the issue.

1 Like

My script fixes the issue as well, though.

Where exactly did I use for loop incorrectly?

2 Likes

now they have exchanged. only one still works, but this time the one that didn’t go before. :joy:
but I’m thinking about a pairs () loop, maybe I’ll come to something.
(I feel like the translator did something wrong with this, is it wrong?)

This gives me an error as at the beginning.
but I’m trying to fix it