i have a script for my gun the only problem is when i die the ammo value doesn't change after i respawn, however everything else still works. it is a server script
local tool = script.Parent
02
03 tool.Equipped:Connect(function()
04 _G.GUI = true
05 while _G.GUI == true do
06 local name = script.Parent.Parent.Name
07 if game.Workspace[tostring(name)].Humanoid.Health <= 0 then
08 _G.GUI = false
09 break
10 else
11 local gungui = game.Players[tostring(name)].PlayerGui:WaitForChild("gungui")
12 local ammo = gungui:WaitForChild("am")
13 local maxammo = gungui:WaitForChild("maxam")
14 local currentammo = gungui:WaitForChild("Currentammo")
15
16 if gungui:FindFirstChild("Currentammo") then
17
18
19 currentammo.Text = ammo.Value .."/".. maxammo.Value
20 wait()
21 end
22
23
24
25 end
26
27
28 end
29 end)
30
31 tool.Unequipped:Connect(function()
32 _G.GUI = false
33 end)
any help would be appreciated :)

4 comments
Does the UI not change, or does the values itself not change?
the ui breaks, the values change however the UI just breaks
are you seeing "script exhaustion timeout" error? if so put a task.wait() or wait() on line 27 in your script since it only waits if gungui:FindFirstChild("Currentammo") but when you die it can't find the child so it does not wait and thus runs too fast.
hello, no i dont receive an error, however it still breaks