Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

my tool text breaks upon dying, can someone please help?

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

0

Does the UI not change, or does the values itself not change?

0

the ui breaks, the values change however the UI just breaks

0

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.

0

hello, no i dont receive an error, however it still breaks

1 answer

if game.Workspace[tostring(name)].Humanoid.Health <= 0 then
_G.GUI = false
break

You're setting the GUI to false if they die?

Even so, I don't see the point of

_G.Gui = true

Then checking if it is true...

Maybe the cause:

you have a break in your script. I'm not sure but consider just getting rid of that, or putting a return in there. Not sure what the return would do but just test it.

This discussion is preserved as it was. New answers, comments, and votes are closed.