Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make a part go towards its orientation?

that is, if it is facing north, it should go north. I am trying to create a gun that shoots bullets,something too basic, without the need to locate the mouse, just shoot where the nozzle of the gun is pointing and the bullet goes in a straight line being anchored. Like a gun in real life Here is the code so you can understand me better

local tool = script.Parent
local bullet = Instance.new("Part")
bullet.Anchored = true
bullet.Name = "bullet"
bullet.Size = Vector3.new(1,1,1)
local Debris = game:GetService("Debris")
tool.Equipped:Connect(function()
	tool["pipupipu's sound"]:Play()
end)

tool.Activated:Connect(function()
	local Newball = bullet:Clone()
	local exist = true
	Newball.CFrame = tool.Disparar.CFrame
	Newball.Parent = game.Workspace
	Debris:AddItem(Newball, 10)
	print(Newball.CFrame.LookVector)
	while Newball do
		wait(0.5)
		Newball.CFrame = CFrame.new(Newball.CFrame.LookVector * 10)
		print(Newball.CFrame)
	end
end)

1 answer

Usually games use the character's camera instead of the actual weapon.

I've never made a script like this and I don't want to give bad advice, so please research more before adding this to your game.

However I have a working code so might as well share it with you

local bullet = Instance.new("Part")
bullet.Size = Vector3.new(1,1,1)
bullet.CanCollide = false
bullet.Parent = workspace
bullet.Name = "Bullet"
bullet.CFrame = CFrame.new(character.Head.Position)
		
bullet.AssemblyLinearVelocity = workspace.Camera.CFrame.LookVector * 100

Velocity is deprecated but I've read that you can use AssemblyLinearVelocity instead. I got the main code from here.

This discussion is preserved as it was. New answers, comments, and votes are closed.