Script:
Ammo = 45
damage = 8
AbleToFire = true
isFiring = true
Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
script.Parent.Equipped:connect(function(eventMouse)
Player:WaitForChild("PlayerGui").ScreenGui3.Frame.Visible = true
eventMouse.Icon = "rbxasset://textures\\GunCursor.png"
local Arm = Player.Character["Right Arm"]
local Torso = Arm.Parent.Torso
local Weld = Player.Character.Torso:WaitForChild("Weld3")
Weld.Part0 = Torso
Weld.Part1 = Arm
Weld.C1 = CFrame.Angles(math.rad(-90), -1, math.rad(0)) * CFrame.new(-1, -0.8, 0.8)
end)
script.Parent.Unequipped:connect(function()
Player:WaitForChild("PlayerGui").ScreenGui3.Frame.Visible = false
local Weld = Player.Character.Torso:WaitForChild("Weld3")
Weld.Part0 = nil
Weld.Part1 = nil
end)
script.Parent.Activated:connect(function()
isFiring = true
repeat wait(.0600)
if Ammo > 0 and AbleToFire == true then
script.Parent.FireSound:Play()
local ray = Ray.new(script.Parent.Handle.CFrame.p, (mouse.Hit.p - script.Parent.Handle.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, Player.Character, false, true)
Bullet = Instance.new("Part", workspace)
game:GetService("Debris"):AddItem("Bullet", 0.1)
Bullet.CanCollide = true
Bullet.BrickColor = BrickColor.new("New Yeller")
Bullet.FormFactor = "Custom"
Bullet.Material = "Neon"
Bullet.CanCollide = true
Bullet.Name = "M4A1Bullet"
local distance = (script.Parent.Handle.CFrame.p - position).magnitude
Bullet.Size = Vector3.new(.2, .2, distance)
Bullet.CFrame = CFrame.new(script.Parent.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
player = game.Players:GetPlayerFromCharacter(part.Parent)
if player.TeamColor ~= Player.TeamColor then
humanoid:TakeDamage(damage)
end
end
end
script.Parent.GripPos = Vector3.new(0.15, -0.4, 0.95)
wait(0)
script.Parent.GripPos = Vector3.new(0.15, -0.4, 1)
Ammo = Ammo - 1
Player.PlayerGui.ScreenGui3.Ammo.Value = Player.PlayerGui.ScreenGui3.Ammo.Value - 1
end
until isFiring == false or Ammo == 0
end)
script.Parent.Deactivated:connect(function()
isFiring = false
end)
mouse.KeyDown:connect(function(Key)
if Key == "r" then
if Ammo <= 44 then
if AbleToFire then
AbleToFire = false
AbleToFire = false
script.Parent.ReloadSound:Play()
wait(1.986)
Ammo = 45
Player.PlayerGui.ScreenGui3.Ammo.Value = 45
AbleToFire = true
end
end
end
end)
That's the script, can someone tell me what I've done wrong or how to fix it? Thanks in all regards.

3 comments
Read below, killerbot29003. I had to put the script in an answer for everything to fit.
You should put that line of code in Line 11. Also, there are chances that the character may not exist before that runs, so you might want to yield until the character is existent.
I tried putting it at line 11, it still didn't work.