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

everytime i respawn my text updating script breaks,can someone help me?

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

0

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()

1 answer

fixed it was to do with my other script for updating theint value

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