Maximum event re-entrancy depth exceeded for Instance.OrientationChanged

Not sure why this error came up, even tho I only change the object position.

My code

-- Tween variable
local tweenFireballRotateInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.In,
	-1,
	true,
	0
)

-- make it rotate
local tween = TweenService:Create(fireball, tweenFireballRotateInfo, {Orientation = Vector3.new(45, 0, 0)})
tween:Play()

-- Make it move
local times = 0
local moveConnection
moveConnection = fireball:GetPropertyChangedSignal("Orientation"):Connect(function()
	times += 1
	fireball.Position = (fireball.CFrame:ToWorldSpace(CFrame.new(0,0,-0.5))).Position
	if times > 300 then
		tween:Destroy()
		fireball:Destroy()
	end
end)

Is there any reason you aren’t just tweening the CFrame property instead of doing the orientation and position seperately?

1 Like

As @Pokemoncraft5290 pointed out, you can just move and rotate the part in the same tween

local tween = TweenService:Create(
	fireball,
	tweenFireballRotateInfo,
	{
		Orientation = Vector3.new(45, 0, 0),
		Position = Vector3.new(50, 10, 0) --Change with wherever you want it to go to
	}
)

and then remove the part of the code that’s causing problems

-- Make it move
local times = 0
local moveConnection
moveConnection = fireball:GetPropertyChangedSignal("Orientation"):Connect(function()
	times += 1
	fireball.Position = (fireball.CFrame:ToWorldSpace(CFrame.new(0,0,-0.5))).Position
	if times > 300 then
		tween:Destroy()
		fireball:Destroy()
	end
end)

(that)

The reason I do this because, I making the fireball that will bounce and go in the straight line. What I did on above code is I make it rotate up and down, then it going to the direction where it pointing toward without the need to change the CFrame.

I am open to any new way to achieve the same result if you have one. Because I have no idea why that error happened.

ball

Similar effect like this but ignore the gravity.

The reason you are having this error is because by changing the Position property of the fireball instance (NOTE: applies only in case if the new one is different from previous) you also affect the Orientation property of the fireball which triggers the same function to be executed again and again.

But I only change the Position and not change the CFrame. How is it affect the Orientation?

Maybe it’s because of

fireball.CFrame:ToWorldSpace(CFrame.new(0,0,-0.5))

try commenting out every line one by one to see what causes it.

fireball.Position = (fireball.CFrame:ToWorldSpace(CFrame.new(0,0,-0.5))).Position

I commented out this line and it’s not error anymore.

Still tho I don’t understand why changing object position impact its orientation.

fireball.CFrame:ToWorldSpace(CFrame.new(0,0,-0.5))

This line that you pointed out only get the CFrame of it but not change it

Getting things can also cause them to be recalculated, for example Humanoid.FloorMaterial is nil until a script tries to get it’s value. I’m not sure what the deal is right here, but you can just replace the code with

local FinishedTween = false
local CompletedConnection = tween.Completed:Connect(function()
    FinishedTween = true
end)

while not FinishedTween do
    fireball.Position = (fireball.CFrame * CFrame.new(0, math.sin(tick()) / 10, 0)).Position
    task.wait()
end

CompletedConnection:Disconnect()
2 Likes