This might be a messy line of code, sorry for that
So I worked on another gun after getting my pistol working and there’s been an issue.
For some reason, the pistol gui doesn’t do this while the sniper gui does.
Basically, when the gun reloads, the text is set to the value, even though the value is bigger than the ammo
Not sure why this happens and I’ve tried practically everything.
local tool = script.Parent
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local playergui = plr.PlayerGui
local firerate = 1
local debounce = false
local maxammo = 2
local value = plr.Inventory.Bullet
local char = plr.CharacterAdded:Wait()
local rt = game.ReplicatedStorage.Shoot
local ammo = 2
tool.Equipped:Connect(function()
screengui1 = game.ReplicatedStorage.AmmoGuiSniper:Clone()
screengui1.Parent = playergui
screengui1.Enabled = true
text = screengui1.Frame.Ammo
end)
tool.Unequipped:Connect(function()
screengui1.Enabled = false
end)
tool.Activated:Connect(function()
if debounce == true then return end
if value.Value == 0 then
text.Text = "Out of Ammo"
return
end
ammo -=1
rt:FireServer(mouse.Hit.Position, script.Parent)
if value.Value > ammo then
text.Text = tostring(ammo) .. "/" .. maxammo
end
if ammo > value.Value then
text.Text = value.Value.. "/" .. maxammo
end
if ammo <= 0 then
text.Text = "Reloading"
task.wait(2)
ammo += 2
if ammo > value.Value then
ammo += 2
text.Text = value.Value.. "/" .. maxammo
end
if value.Value > ammo then
ammo += 2
text.Text = ammo .. "/" .. maxammo
end
end
debounce = true
task.wait(firerate)
debounce = false
end)