i’m using an old RRP2 gun system edited for FE as the basis for my gun system. The code is around 80% the same as the original one. The problem is that I don’t understand why adding for i = 1,12 do
to the same area as the original gun system to create a shotgun effect with multiple bullets breaks the gun. The only error I got was that I didn’t add an end
. When I did add it, it still broke. Help?
FE-Edited Code:
if Handle:FindFirstChild('FireSound') then
remot:FireServer(Player)
remote:FireServer(Player)
end
if MyMouse then
for i = 1,12 do
RecoilTrack:Play()
local targetPoint = MyMouse.Hit.p
local shootDirection = (targetPoint - Handle.Position).unit
-- Adjust the shoot direction randomly off by a little bit to account for recoil
shootDirection = CFrame.Angles((0.5 - math.random()) * 2 * Spread,
(0.5 - math.random()) * 2 * Spread,
(0.5 - math.random()) * 2 * Spread) * shootDirection
Camera.CFrame = Camera.CFrame * CFrame.Angles(0.3,math.rad(0),0)
local randomnumber = math.random(1, 2)---randomized horizontal recoil
if randomnumber == 2 then
Camera.CFrame = Camera.CFrame * CFrame.Angles(0,math.rad(10),0)
end
if randomnumber == 1 then
Camera.CFrame = Camera.CFrame * CFrame.Angles(0,math.rad(-10),0)
end
local hitObject, bulletPos = RayCast(Handle.Position, shootDirection, Range)
local bullet
-- Create a bullet here
if hitObject then
bullet = CreateBullet(bulletPos)
local randomnumber = math.random(1, 3)---randomized blood hit sound
if randomnumber == 3 then
script.Parent.Handle.BulletCracks.Crack3:Play()
end
if randomnumber == 2 then
script.Parent.Handle.BulletCracks.Crack2:Play()
end
if randomnumber == 1 then
script.Parent.Handle.BulletCracks.Crack1:Play()
end
game.Debris:AddItem(bg, 0.15)
end
if hitObject and hitObject.Parent then
local hitHumanoid = hitObject.Parent:FindFirstChild("Humanoid")
if hitHumanoid then
local hitPlayer = game.Players:GetPlayerFromCharacter(hitHumanoid.Parent)
if MyPlayer.Neutral or hitPlayer then
TagHumanoid(hitHumanoid, MyPlayer)
script.Parent.DamageEvent:FireServer(hitHumanoid)
if bullet then
bullet.BrickColor = BrickColor.new("Maroon")
bullet.Material = "Pebble"
local randomnumber = math.random(1, 3)---randomized blood hit sound
if randomnumber == 3 then
script.Parent.Handle.HitSounds.BloodHit3:Play()
end
if randomnumber == 2 then
script.Parent.Handle.HitSounds.BloodHit2:Play()
end
if randomnumber == 1 then
script.Parent.Handle.HitSounds.BloodHit1:Play()
end
end
Spawn(UpdateTargetHit)
The original code:
function OnFire()
if IsShooting then return end
if MyHumanoid and MyHumanoid.Health > 0 then
if RecoilTrack and AmmoInClip > 0 then
RecoilTrack:Play()
end
IsShooting = true
while LeftButtonDown and AmmoInClip > 0 and not Reloading do
if Spread and not DecreasedAimLastShot then
Spread = math.min(MaxSpread, Spread + AimInaccuracyStepAmount)
UpdateCrosshair(Spread)
end
DecreasedAimLastShot = not DecreasedAimLastShot
if Handle:FindFirstChild('FireSound') then
Handle.FireSound:Play()
Handle.Flash.Enabled = true
end
if MyMouse then
for i = 1,12 do -- Shotgun effect :P
local targetPoint = MyMouse.Hit.p
local shootDirection = (targetPoint - Handle.Position).unit
-- Adjust the shoot direction randomly off by a little bit to account for recoil
shootDirection = CFrame.Angles((0.5 - math.random()) * 2 * Spread,
(0.5 - math.random()) * 2 * Spread,
(0.5 - math.random()) * 2 * Spread) * shootDirection
local hitObject, bulletPos = RayCast(Handle.Position, shootDirection, Range)
local bullet
-- Create a bullet here
if hitObject then
bullet = CreateBullet(bulletPos)
end
if hitObject and hitObject.Parent then
local hitHumanoid = hitObject.Parent:FindFirstChild("Humanoid")
if hitHumanoid then
local hitPlayer = game.Players:GetPlayerFromCharacter(hitHumanoid.Parent)
if MyPlayer.Neutral or hitPlayer then
TagHumanoid(hitHumanoid, MyPlayer)
hitHumanoid:TakeDamage(Damage)
if bullet then
bullet:Destroy()
bullet = nil
--bullet.Transparency = 1
end
Spawn(UpdateTargetHit)
elseif not hitPlayer then
TagHumanoid(hitHumanoid, MyPlayer)
hitHumanoid:TakeDamage(Damage)
if bullet then
bullet:Destroy()
bullet = nil
--bullet.Transparency = 1
end
Spawn(UpdateTargetHit)