I just came across the FastCast module the other day and wanted to add onto the script so that the gun could have an ammo GUI and also have a reload system that can keep one bullet in the chamber. The gun starts off with 0 bullets in the magazine. When I reload it, it reloads but it doesn't subtract the 1 bullet that isn't in the chamber. I fire a couple shots, and when I try to reload again, the game reload event fires but the Mag.Changed:Connect(function() doesn't connect. Here's what I tried to do:
Client Script:
CanReload = false
function OnEquipped(playerMouse)
CanReload = true
local clone = GUI:Clone()
local TextLabel = clone:WaitForChild("TextLabel")
TextLabel.Text = Mag.Value.."/"..Mag.MaxValue
clone.Parent = Player.PlayerGui
Mouse = playerMouse
ExpectingInput = true
UpdateMouseIcon()
end
function OnUnequipped()
CanReload = false
if Player.PlayerGui:FindFirstChild("Magazine") then
Player.PlayerGui.Magazine:Destroy()
end
ExpectingInput = false
UpdateMouseIcon()
end
Tool.Equipped:Connect(OnEquipped)
Tool.Unequipped:Connect(OnUnequipped)
local reloaddebounce = false
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.R then
if CanReload then
if not reloaddebounce then
print("reloading")
reloaddebounce = true
Reload:FireServer(Tool)
wait(1)
reloaddebounce = false
end
end
end
end)
UserInputService.InputBegan:Connect(function (input, gameHandledEvent)
if gameHandledEvent or not ExpectingInput then
return
end
if input.UserInputType == Enum.UserInputType.MouseButton1 and Mouse ~= nil then
local FireDirection = (Mouse.Hit.Position - FirePointObject.WorldPosition).Unit
local Mag = Tool:FindFirstChild("Mag")
if not Mag then return end
if Mag.Value <= 0 then
print("Out Of Ammo")
else
MouseEvent:FireServer(FireDirection)
Mag.Value = Mag.Value - 1
end
end
end)
Mag.Changed:Connect(function()
if Player.PlayerGui:FindFirstChild("Magazine") and Player.PlayerGui:FindFirstChild("Magazine"):FindFirstChild("TextLabel") then
Player.PlayerGui.Magazine.TextLabel.Text = Mag.Value.."/"..Mag.MaxValue
end
end)
Server script:
ReloadEvent.OnServerEvent:Connect(function(Player,Tool)
local Mag = Tool:WaitForChild("Mag")
if not Mag then return end
if Mag.Value <= 0 then
Mag.Value = Mag.MaxValue - 1
else
Mag.Value = Mag.MaxValue
end
end)

1 comment
I tried changing it to FindFirstChild and heeded no results. Also, line 4 and 5 is detecting if the ammo is at 0 so the server can reload the magazine minus 1 because there's no round in the chamber. The MouseEvent is handling the shots fired and subtracts 1 from the Mag.Value each time the player presses MouseButton1. Thanks for trying to help, though.