So the problem resides with line 52 and line 58.
I'm trying to make it so once a shot is fired the tools name turns to the word Pistol and then the amount of ammo.
I'm also trying to make it to where when you press the R key it reloads. This works but after I press R I need to click the mouse in order to reload.
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local ammo = 8
local isReload = false
local mouse = game.Players.LocalPlayer:GetMouse()
tool.Equipped:connect(function(mouse)
print("Pistol Equipped")
mouse.Button1Down:connect(function()
print("Mouse Clicked")
if (not isReload) and ammo > 0 then --if Player is not reloading
ammo = ammo - 1
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 200)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Gray")
beam.FormFactor = "Custom"
beam.Material = "Neon"
beam.Transparency = 0.75
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local light = Instance.new("PointLight", beam)
light.Range = 15
local distance = (tool.Handle.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, - distance / 2)
game:GetService("Debris"):AddItem(beam, 0.1)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
humanoid:TakeDamage(30)
end
end
else
tool.Name = "Reloading"
isReload = true
wait(2)
tool.Name = ("Pistol " .. ammo) -- Name of tool is "Pistol (amount of ammo)
ammo = 8
print("Reloaded")
isReload = false
end
mouse.KeyDown:connect(function (r) --Reloading with r key Function
isReload = true
end)
end)
end)
Sorry if this doesn't make sense.

1 comment
Bout time you actually did something useful with ye life