Incredibly strange, ammo is only subtracting once. It was working fine 2 days ago as well? Anyways, that’s all I have to say about the issue, here’s the server script:
local rt = game:GetService("ReplicatedStorage"):WaitForChild("Shoot")
local reloadrt = game.ReplicatedStorage.Reload
local debris = game:GetService("Debris")
local gunshot = game:GetService("SoundService"):WaitForChild("Gun Shot")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://13112812781"
local reload = game.SoundService["Pistol Reload Sound"]
rt.OnServerEvent:Connect(function(plr, mouse, tool)
local bullets = plr.Inventory.Bullet
local char = plr.Character
local hum = char.Humanoid
local animator = hum.Animator
local effect = tool.Effect.MuzzleEffect
if tool.Name == "Pistol" then
local damage = 10
local debounce = false
local ammo = script.Ammo.Value
local ammo_out = false
local firerate = 0.5
local debounce2 = false
if debounce == false and ammo_out == false and bullets.Value > 0 then
reloadrt.OnServerEvent:Connect(function(plr)
print("for")
local reloadanim = Instance.new("Animation")
reloadanim.AnimationId = "rbxassetid://13133924759"
reloadanim.Parent = script
local loadanim = char.Humanoid.Animator:LoadAnimation(reloadanim)
reload:Play()
ammo_out = true
loadanim:Play()
effect.Enabled = false
task.wait(2)
ammo = 16
reload:Stop()
reloadanim:Destroy()
ammo_out = false
end)
local loadanim = animator:LoadAnimation(animation)
loadanim:Play()
gunshot:Play()
bullets.Value -=1
print(mouse)
local bullet = Instance.new("Part")
bullet.Size = Vector3.new(1,1,1)
bullet.Position = mouse
bullet.Transparency = 1
bullet.CanCollide = true
bullet.Parent = workspace
ammo -=1
print(tostring(ammo))
bullet.Touched:Connect(function(hit)
print("hit")
if hit.Parent:FindFirstChild("Humanoid") then
warn("hum")
if debounce2 == false then
if hit.Parent.Name == plr.Character.Name then return end
hit.Parent.Humanoid:TakeDamage(damage)
print("wow")
debounce2 = true
end
else
warn("no hum")
end
end)
debris:AddItem(bullet, firerate)
effect.Enabled = true
if ammo <= 0 then
local reloadanim = Instance.new("Animation")
reloadanim.AnimationId = "rbxassetid://13133924759"
reloadanim.Parent = script
local loadanim = char.Humanoid.Animator:LoadAnimation(reloadanim)
reload:Play()
print("reload")
ammo_out = true
loadanim:Play()
effect.Enabled = false
while true do
ammo = 0
task.wait(2)
break
end
ammo += 2
reload:Stop()
reloadanim:Destroy()
ammo_out = false
end
debounce = true
print("debounce1")
task.wait(firerate)
debounce = false
effect.Enabled = false
print("debounce 2")
end
end
end)
Here is the local script:
local rt = game:GetService("ReplicatedStorage"):WaitForChild("Shoot")
local remaining = game.ReplicatedStorage.Remaining
print("inf")
local reloadrt = game.ReplicatedStorage.Reload
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local plr = game:GetService("Players").LocalPlayer
local tool = script.Parent
local playergui = plr.PlayerGui
local debouncereload = false
local uis = game:GetService("UserInputService")
local debounce = false
local value = plr.Inventory.Bullet
local char = plr.CharacterAdded:Wait()
local ammo_out = false
local rt = game.ReplicatedStorage.Shoot
local ammo = 16
tool.Equipped:Connect(function()
screengui1 = game.ReplicatedStorage.AmmoGui:Clone()
screengui1.Parent = playergui
screengui1.Enabled = true
text = screengui1.Frame.Ammo
text.Text = tostring(ammo) .. "/16"
if value.Value <= ammo then
text.Text = tostring(value.Value) .. "/16"
end
if value.Value <=0 then
text.Text = "Out of Ammo"
text.TextColor3 = Color3.new(1, 0, 0)
value.Changed:Connect(function()
text.Text = tostring(value.Value) .. "/16"
text.TextColor3 = Color3.new(1, 1, 1)
end)
end
end)
tool.Unequipped:Connect(function()
screengui1.Enabled = false
print("em")
end)
tool.Activated:Connect(function()
print("oh")
print(ammo .. ": From the Client, ammo value")
print(value.Value .. ": From the Client, bullet value")
if debounce == false and ammo_out == false then
if value.Value < ammo then
text.TextColor3 = Color3.new(1, 1,1)
print("aa")
rt:FireServer(mouse.Hit.Position, script.Parent)
text.Text = tostring(value.Value) .. "/16"
print("baaaa")
end
if value.Value <=0 or ammo <= 0 then
print("AHEM")
text.Text = "Out of Ammo"
print(text.Text)
text.TextColor3 = Color3.new(1, 0, 0)
return
end
if ammo < value.Value then
text.Text = tostring(ammo) .. "/16"
print("high and low")
text.TextColor3 = Color3.new(1, 1,1)
print("aa")
rt:FireServer(mouse.Hit.Position, script.Parent)
ammo -=1
print("sent")
end
if ammo == 0 then
ammo_out = true
text.Text = "Reloading..."
print("ay")
task.wait(2)
ammo = 16
if value.Value < ammo then
print("bee")
text.Text = value.Value .. "/16"
ammo_out = false
return
end
print("B OO")
ammo_out = false
text.Text = "16/16"
end
debounce = true
task.wait(0.5)
debounce = false
end
end)
uis.InputBegan:Connect(function(input, istyping)
if istyping then return end
if input.KeyCode == Enum.KeyCode.R then
if value.Value <=0 then return end
if ammo == 16 then return end
if debounce == false then
reloadrt:FireServer()
ammo_out = true
text.Text = "Reloading..."
task.wait(2)
ammo_out = false
text.Text = "16/16"
ammo = 16
debounce = true
task.wait(1)
debounce = false
end
end
end)