When I click, the bullet doesn't go straight. Instead, it comes out different ways. I don't know why it does this. Help?
local tool = script.Parent
local reloading = script.Parent.Reloading
local autofire = false
function fireBullet(d)
local bullet = Instance.new("Part")
bullet.FormFactor = "Custom"
bullet.Size = Vector3.new(1.5, 0.35, 0.35)
bullet.BrickColor = BrickColor.new("White")
bullet.Position = tool.Handle.Position + (d * 5)
bullet.Velocity = d * 125
local s = script.RemoveBullet:Clone()
s.Disabled = false
s.Parent = bullet
local force = Instance.new("BodyForce")
force.force = Vector3.new(0, 25, 0)
force.Parent = bullet
bullet.Parent = game.Workspace
end
function semiFire(d)
fireBullet(d)
end
function burstFire(d)
for i = 1, 3 do
fireBullet(d)
wait(0.15)
end
end
function autoFire(hum, chr)
while autofire do
local targetPos = hum.TargetPoint
local lookAt = (targetPos - chr.Head.Position).unit
fireBullet(lookAt)
wait(0.1)
end
end
tool.Activated:connect(function()
if tool.Enabled and not reloading.Value then
local chr = tool.Parent
if game.Players:GetPlayerFromCharacter(chr) == script.Parent.plr.Value then
if chr:FindFirstChild("Humanoid") then
if chr.Humanoid.Health > 0 then
reloading.Value = true
local hum = chr.Humanoid
local targetPos = hum.TargetPoint
local lookAt = (targetPos - chr.Head.Position).unit
local mode = tool.Parent.gunmode.Value
if mode == 1 then
--Semiautomatic firing
semiFire(lookAt)
wait(0.5)
elseif mode == 2 then
--Burst firing
burstFire(lookAt)
wait(1)
else
--Automatic firing
autofire = true
autoFire(hum, chr)
end
reloading.Value = false
end
end
end
end
end)
tool.Deactivated:connect(function()
autofire = false
end)

3 comments
uh.... ok?? thanks mr. scientist.
Wait, this still doesn't work...
Nope.