Hi. I cannot seem to find any other way to keep my rotation locked in the correct rotation during a tween teleport. My rotation when I am tweening only works when I loop CFrame the CFrame and Rotation during the course of a tween by using this coroutine wrap function
coroutine.wrap(function()
while Part ~= nil do
task.wait()
Part.CFrame = CFrame.lookAt(attachment.WorldPosition, direction) * CFrame.Angles(0, 0, 0)
end
end)()
If someone could please help me use an alternative that doesn’t require me to use a coroutine wrap function that would be great. Thank you so much!
A coroutine wrap specifically the way I used it allows the rest of the code to run while doing a loop so that the code doesn’t just stop at the loop. I need the loop to loop the CFrame of the bullet so it is rotated correctly. The CFrame is not actually moving because the game isn’t recognizing it because it is inside of a coroutine wrap function. It allows it to visually show it is moving but the actual CFrame is never changing only visually it is. Because of this problem, I can’t get the touched function for the bullets to work correctly. I’m also having an issue with the touched so these two issues are kind of hand and hand with each other. but this one would be great to get fixed first before we move to that second issue I’m having
Pretty much. It never actually moves the CFrame of the bullet. It only does it visually and this is problematic for a lot of reasons. However, I can’t take it away until there is an alternative because the while loop would stop the rest of my code from running
try replacing coroutine.wrap with task.spawn, its pretty much the same thing, would look something like this
task.spawn(function()
while Part ~= nil do
task.wait()
Part.CFrame = CFrame.lookAt(attachment.WorldPosition, direction) * CFrame.Angles(0, 0, 0)
end
end)
Yes I want it to only be rotated towards the direction is going and so far the only way I have been able to do this is by looping it with the tween teleport
Yes that is exactly right. The touch event only works properly if the code is not in a task.spawn or a coroutine wrap, and surely I can do that, at the expense of the bullets endlessly rotating forward.
local Bullet -- Instance the bullet
task.spawn(function()
while Bullet ~= nil do
task.wait()
Bullet.CFrame = CFrame.lookAt(attachment.WorldPosition, direction) * CFrame.Angles(0, 0, 0)
end
end)
local Att = --Instance the attachment
local LV = --Instance the linear velocity
--LV and Att work to keep the bullet in the air because the bullet is unanchored and will fall if there is no velocity
local movement: Tween = game:GetService("TweenService"):Create(Bullet, TweenInfo.new(20), {Position = direction})
movement:Play() --Moves the bullet
task.wait() --Must wait for the unanchor to work
--Unanchor the bullet
--Touched function which cannot detect the CFrame of the bullet. It believes the CFrame is what it is before the Tween actually occurred
The exact code is not necessary to fix this problem. Step by step that is how my code is ordered and step by step that is what the problem is and how it occurs
Thank you so much for coming to help. I really appreciate that because it’s the extra little explanations like that which help me even further to understand in the future how to prevent this problem from happening. Cheers