Tween/Cframe not working properly

You can write your topic however you want, but you need to answer these questions:

  1. So, I have a CIWS antiaircraft with a bullet welded to the barrel and I have a tween for shooting it.

  2. However, when I test it, is goes way out to the side


  3. I tried asking chat gpt, reviewing my code, and I’ve spent a long time trying to fix this. Any suggestions?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is my code

local debrisService = game:GetService("Debris")

while true do
	local clone = script.Parent.Bullet:Clone()
	clone.Parent = game.Workspace
	clone:breakJoints()
	clone.Anchored = true
	local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
	local tween = game:GetService("TweenService"):Create(clone, tweenInfo, {Position = (script.Parent.Bullet.CFrame.LookVector* 10)})
	script.Parent.Attachment.FX:Emit(1)
	tween:Play()
	clone.Trail.Enabled = true
	script.Parent.FlashFX.Enabled = true
	task.delay(1, function()
	clone.Touched:Connect(function(hit)
		if hit.Name ~= "Bullet" and hit.Name ~= "barrel" then
			local explosion = Instance.new("Explosion")
			explosion.Position = clone.Position
			explosion.Parent = game.Workspace
			explosion.BlastRadius = 10
			explosion.Visible = true
			explosion.BlastPressure = 0
			clone:Destroy()
		end
		end)
	end)
	wait()
	script.Parent.FlashFX.Enabled = false
	debrisService:AddItem(clone, 3)
end

The lookVector only describes the direction of the turret, and it does not include the starting position. This would totally break where the bullets travel towards. To add the starting position into the final position, all you do is add its position to the direction vector:

local tween = game:GetService("TweenService"):Create(clone, tweenInfo, {Position = (script.Parent.Bullet.CFrame.LookVector* 10 + script.Parent.Bullet.Position)})

thank you for the feedback, this works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.