Turret Bullets Not Firing

Hello all. I was making a turret for fun, and this is one of my first times ever using LinearVelocity/BodyVelocity, so it would be a nice experiment. I want for the bullets from the turret to be able to go in the direction that it is facing via a part named “BulletDockingPos” that is stationed at the tip. However, I can’t seem to get my bullets off the ground or even moving in that general direction. Any help is appreciated, thank you.


Script:

local function fireTurret()
	repeat
		game.Workspace.Turret.MainTurret:SetPrimaryPartCFrame(game.Workspace.Turret.MainTurret.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(1)))

		task.wait()
		
		local bullet = game.ServerStorage.Bullet:Clone()
		bullet.Parent = game.Workspace.Turret.Bullets
		bullet.CFrame = game.Workspace.Turret.MainTurret.BulletDockingPos.CFrame
		
		local linearVelocity = Instance.new("LinearVelocity")
		linearVelocity.Parent = bullet
		linearVelocity.LineDirection = game.Workspace.Turret.MainTurret.BulletDockingPos.CFrame.LookVector
		linearVelocity.LineVelocity = game.Workspace.Turret.MainTurret.BulletDockingPos.CFrame.LookVector * 2

		game.Workspace.Turret.MainTurret:SetPrimaryPartCFrame(game.Workspace.Turret.MainTurret.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(-1)))

		task.wait()
	until fStopped == true
end
1 Like

I’m not able to help you because I’m still a beginner scripter, but to help others could you just copy/paste the code using the DevForum script? It looks like this:

your code goes in here

and you write it like this:

1 Like

Yes, you would be able to do that via a DevForum Script.

Yeah, I mean put it in a DevForum script so people can understand it easier because the images with scripts always have low quality and it’s hard for people to understand it
Edit:

Thanks for doing this :slightly_smiling_face:

Apologies, I misunderstood. It’s now there in the format you spoke of.

Normal, misunderstanding is human

Instead of using bullet.CFrame, use bullet.Position and don’t forget to say bullet:SetNetworkOwner(player)

This object is deprecated and should not be used for new work. Use LinearVelocity instead.

- BodyVelocity Documentation

@RamonPIayz LinearVelocity Instances also require an Attachment to be able to assign the object from, so you’ll have to create one & Parent it within your Bullet as well

You may also have to tweak the CFrame values in order to properly get the Part to shoot in the direction of where the Turret is currently aiming

local function fireTurret()
	repeat
		game.Workspace.Turret.MainTurret:SetPrimaryPartCFrame(game.Workspace.Turret.MainTurret.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(1)))

		local bullet = game.ServerStorage.Bullet:Clone()
		bullet.Parent = game.Workspace.Turret.Bullets
		bullet.CFrame = workspace.Turret.MainTurret.BulletDockingPos.CFrame
	
		local linearVelocity = Instance.new("LinearVelocity")
		linearVelocity.Parent = bullet
		linearVelocity.LineDirection = bullet.CFrame.LookVector
		linearVelocity.LineVelocity = bullet.CFrame.LookVector * 2

		local A = Instance.new("Attachment")
		A.Parent = linearVelocity
		
		game.Workspace.Turret.MainTurret:SetPrimaryPartCFrame(game.Workspace.Turret.MainTurret.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(-1)))

		task.wait()
	until fStopped == true
end
2 Likes

Oh, BodyVelocity is deprecated? Alright thanks for the info.

Thank you so much, I’ll take this advice with me for the future and elsewhere!! Your help is much appreciated!!

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