-- 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)
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)
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.
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.
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()