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

My gun bullets are going the wrong way, Any way to stop this?

script.Parent.Fire.OnServerEvent:Connect(function()
	local bullet = Instance.new("Part",workspace)
	bullet.BrickColor = BrickColor.Random()
	bullet.Position = script.Parent.Handle.Pointer.Position
	bullet.Anchored = true
	bullet.Size = Vector3.new(0.5, 0.5, 1)
	bullet.Shape = "Cylinder"
	for i = 1,100 do
		if bullet == nil then
			break
		end
		print (bullet.Position)
		bullet.CFrame = bullet.CFrame  + Vector3.new(0,0,1.22)
		if i == 99 then
			bullet:Destroy()
		end
		wait ()
	end
end)

Problem with the script is when i aim at a other direction it keeps aimming to south even if i point the gun to east,north,west

2 comments

0

I think you should change this line of code "bullet.CFrame = bullet.CFrame + Vector3.new(0,0,1.22)"

0

I dont know anything to change there. Can you try helping out

1 answer

✓ Accepted answer

Assuming you will be using something to 'push' the bullet forward. Instead of Bullet.CFrame + Bullet.CFrame, try CFrame.new()

CFrame.new(startPosition, lookVector) -- First parameter being where it should be positioned, second being where it should be pointing. So, applying it to your script should look something like this:

script.Parent.Fire.OnServerEvent:Connect(function()
    local bullet = Instance.new("Part",workspace)
    bullet.BrickColor = BrickColor.Random()
    bullet.Anchored = true
    bullet.Size = Vector3.new(0.5, 0.5, 1)
    bullet.Shape = "Cylinder"
    for i = 1,100 do
        if bullet == nil then
            break
        end
        print (bullet.Position)
	-- Change lookVector to where you want the bullet to face. lookVector also uses position.
        bullet.CFrame = CFrame.new(script.Parent.Handle.Pointer.Position + Vector3.new(0,0,1), lookVector)
        if i == 99 then
            bullet:Destroy()
        end
        wait ()
    end
end)

You can read more up on CFrame here and here.

3 comments

0

I dont know what to change at the lookVector. Example?

0

I tried vector3.new(1,0,0) but now my bullets are following the gun

0

Change the lookVector to the position of where you want the bullet to face.

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