Tried creating a gun. I did it, but there is a bug. So whenever you shoot the gun, it wastes 1 bullet, obviously, and when the gun has 0 bullets, it reloads of course. BUT, wheneveryou unequip the weapon and re equip it, whenever you shoot, you lose and extra bullet. Lets say the gun wastes 1 bullet when shot, i unequip, then re equip, and then the gun starts losing 2 bullets per shot? I do that again, then it starts wasting 3 bullets per shot. Here is the local script:
local mouse = game.Players.LocalPlayer:GetMouse()
local tool = script.Parent
local Player = game.Players.LocalPlayer
local Char = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Char:WaitForChild(“Humanoid”)local enabled = true
local maxAmmo = tool.Handle:WaitForChild(“maxAmmo”)
local fullammo = truetool.Equipped:Connect(function()
local LoadHumAnim = Humanoid.Animator:LoadAnimation(script.Idle)
LoadHumAnim:Play()local UserInputService = game:GetService(“UserInputService”)
– A sample function providing one usage of InputBegan
local function onInputBegan(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.R thenif maxAmmo.Value < 10 and maxAmmo.Value > 0 then enabled = false tool.Handle.Reload:Play() local LoadHumAnim = Humanoid.Animator:LoadAnimation(script.Reload) LoadHumAnim:Play() wait(2.2) maxAmmo.Value = 10 enabled = true end end tool.Unequipped:Connect(function() LoadHumAnim:Stop() end)
end
UserInputService.InputBegan:Connect(onInputBegan)
script.Parent.Activated:Connect(function()
if enabled == true then wait(.2) script.Parent.Fire:FireServer(mouse.Hit.p) tool.Handle.Fire:Play() maxAmmo.Value -= 1 local LoadHumAnim = Humanoid.Animator:LoadAnimation(script.Fire) LoadHumAnim:Play() if maxAmmo.Value < 1 then enabled = false tool.Handle.Reload:Play() local LoadHumAnim = Humanoid.Animator:LoadAnimation(script.Reload) LoadHumAnim:Play() wait(2.2) maxAmmo.Value = 10 enabled = true end end
end)
end)
Please help!