Hello, I’m working on a weapon, but I have a problem, I’m using two values to set Ammo count and number of Shot x click, but every time Unequip and then Equip the Item, the shot number become 1 more high, can someone help me ?
local Tool = script.Parent
local Ammo = script.Parent:WaitForChild("Ammo", 1)
local Shot = script.Parent:WaitForChild("Shot", 1)
local Value = script.Parent:WaitForChild("Value")
local reloading = false
local plr = game.Players.LocalPlayer
local GUI = script.Parent:WaitForChild("AmmoGUI", 1)
local UIS = game:GetService("UserInputService")
local CAS = game:GetService("ContextActionService")
Tool.Equipped:Connect(function(Mouse)
Ammo.Value = 10
Shot.Value = 1
Value.Value = true
reloading = false
GUI:Clone().Parent = plr.PlayerGui
wait()
local text = plr.PlayerGui:FindFirstChild("AmmoGUI"):FindFirstChild("Frame"):FindFirstChild("Ammo")
text.Text = (Ammo.Value).." / "..10
local function reload()
reloading = true
wait(1)
script.Parent.Reload:Play() -- change reloadingsound to what ever your reload sound is named
Ammo.Value = 10
Shot.Value = 1
reloading = false
end
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and Value.Value == true then
if Ammo.Value > 0 and not reloading then
Ammo.Value = Ammo.Value - Shot.Value
script.Parent.ShotSound:Play() -- change gunshot to what ever your gun shot sound is named
elseif reloading == false then
reload()
script.Parent.ShotSound:Stop()-- change gunshot to what ever your gun shot sound is named
end
while wait() do
text.Text = (Ammo.Value).." / "..10
end
end
end)
UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R and reloading == false and Ammo.Value ~= 10 and Value.Value == true then
reload()
end
end)
end)
Tool.Unequipped:Connect(function()
if plr.PlayerGui:FindFirstChild("AmmoGUI") then
plr.PlayerGui:FindFirstChild("AmmoGUI"):Destroy()
end
Value.Value = false
reloading = false
end)