So i have a script for my gun the only problem is when i die the ammo value doesn't change after i re spawn, however everything else still works. it is a server script
local tool = script.Parent
tool.Equipped:Connect(function()
_G.GUI = true
while _G.GUI == true do
local name = script.Parent.Parent.Name
if game.Workspace[tostring(name)].Humanoid.Health <= 0 then
_G.GUI = false
break
else
local gungui = game.Players[tostring(name)].PlayerGui:WaitForChild("gungui")
local ammo = gungui:WaitForChild("am")
local maxammo = gungui:WaitForChild("maxam")
local currentammo = gungui:WaitForChild("Currentammo")
if gungui:FindFirstChild("Currentammo") then
currentammo.Text = ammo.Value .."/".. maxammo.Value
wait()
end
end
end
end)
tool.Unequipped:Connect(function()
_G.GUI = false
end)
thankyou for reading, any help would be appreciated :)

1 comment
1 - just make the _G.GUI a local outside every scope (aka just under the tool variable). I don't see the point in adding it there-...And also make sure you do a CharacterAdded event so this will re-run everytime you respawn. I'm at school rn so I can't look further into this as of now, but try making it in a different way. Like checking for any values changing via :GetPropertyChangedSignal()