ArmorBar GUI doesnt work after respawn - help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix the bargui to make it work after the respawn

  2. What is the issue? Include screenshots / videos if possible!
    So whenever i rest only the healthbar gui it does reset
    and the bargui(blue gui) it doesnt reset when i respawn

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    So far i tried to ask AI assistant from the roblox one and it gave me no solution


local char = plr.Character or plr.CharacterAdded:Wait()

local curArmour = char:FindFirstChild('Armour')
local maxArmour = char:FindFirstChild('MaxArmour')

local OArmour = char:FindFirstChild('OArmour')
local OMaxArmour = char:FindFirstChild('OMaxArmour')

repeat wait()
	curArmour = char:FindFirstChild('Armour')
	maxArmour = char:FindFirstChild('MaxArmour')
	script.Parent.MainFrame.Visible = false
	OMaxArmour = char:FindFirstChild('OMaxArmour')
	OArmour = char:FindFirstChild('OArmour')
until (curArmour and maxArmour) or (OArmour and OMaxArmour)

if curArmour and maxArmour and not (OArmour and OMaxArmour) then
	script.Parent.MainFrame.Visible = true
	script.Parent.MainFrame.Holder.Bar.Size = UDim2.new((curArmour.Value/maxArmour.Value) * 1.013, 0,0.663, 0)
	
	script.Parent.MainFrame.Holder.PercentageDisplay.Text = math.floor(curArmour.Value*10) / 10 .. "/" .. maxArmour.Value
	
	curArmour.Changed:Connect(function()
		script.Parent.MainFrame.Holder.Bar.Size = UDim2.new((curArmour.Value/maxArmour.Value) * 1.013, 0,0.663, 0)
		script.Parent.MainFrame.Holder.PercentageDisplay.Text = math.floor(curArmour.Value*10) / 10 .. "/" .. maxArmour.Value
	end)
end

if OArmour and OMaxArmour then
	if OMaxArmour == 0 then
		script.Parent.MainFrame.Visible = false
		return
	end
	script.Parent.MainFrame.Visible = true
	script.Parent.MainFrame.Holder.Bar.Size = UDim2.new((OArmour.Value/OMaxArmour.Value) * 1.013, 0,0.663, 0)

	script.Parent.MainFrame.Holder.PercentageDisplay.Text = math.floor(OArmour.Value*10) / 10 .. "/" .. OMaxArmour.Value

	OArmour.Changed:Connect(function()
		script.Parent.MainFrame.Holder.Bar.Size = UDim2.new((OArmour.Value/OMaxArmour.Value) * 1.013, 0,0.663, 0)
		script.Parent.MainFrame.Holder.PercentageDisplay.Text = math.floor(OArmour.Value*10) / 10 .. "/" .. OMaxArmour.Value
	end)
en

the blue bar gui
image

the first bar gui is the healthbar

does the ScreenGui have ResetOnSpawn enabled?

Hi yes it does but still no working at all

You should probably try and make it so it checks with the plr.CharacterAdded event instead

Im sorry to ask but im not a scripter how do u want me to do that?

tldr;
plr.CharacterAdded is an event that fires everytime a new character in the player has spawned
example:

plr.CharacterAdded:Connect(function(char)
	print(char) -- prints the new character
end)

At what line of the code do you want me to add this

when you spawn for the first time, does the script work as intended?

The script work fine its for the gun system to shoot an player with the numbers of armor they have
the only issue is that when i respawn the bar gui it doesnt reset like healthbar gui

Krept where do u want me to add that line of the code? like which line of the number

try this:

local plr = game.Players.LocalPlayer

plr.CharacterAdded:Connect(function(char)
	local curArmour = char:FindFirstChild('Armour')
	local maxArmour = char:FindFirstChild('MaxArmour')

	local OArmour = char:FindFirstChild('OArmour')
	local OMaxArmour = char:FindFirstChild('OMaxArmour')

	repeat wait()
		curArmour = char:FindFirstChild('Armour')
		maxArmour = char:FindFirstChild('MaxArmour')
		script.Parent.MainFrame.Visible = false
		OMaxArmour = char:FindFirstChild('OMaxArmour')
		OArmour = char:FindFirstChild('OArmour')
	until (curArmour and maxArmour) or (OArmour and OMaxArmour)

	if curArmour and maxArmour and not (OArmour and OMaxArmour) then
		script.Parent.MainFrame.Visible = true
		script.Parent.MainFrame.Holder.Bar.Size = UDim2.new((curArmour.Value/maxArmour.Value) * 1.013, 0,0.663, 0)

		script.Parent.MainFrame.Holder.PercentageDisplay.Text = math.floor(curArmour.Value*10) / 10 .. "/" .. maxArmour.Value

		curArmour.Changed:Connect(function()
			script.Parent.MainFrame.Holder.Bar.Size = UDim2.new((curArmour.Value/maxArmour.Value) * 1.013, 0,0.663, 0)
			script.Parent.MainFrame.Holder.PercentageDisplay.Text = math.floor(curArmour.Value*10) / 10 .. "/" .. maxArmour.Value
		end)
	end

	if OArmour and OMaxArmour then
		if OMaxArmour == 0 then
			script.Parent.MainFrame.Visible = false
			return
		end
		script.Parent.MainFrame.Visible = true
		script.Parent.MainFrame.Holder.Bar.Size = UDim2.new((OArmour.Value/OMaxArmour.Value) * 1.013, 0,0.663, 0)

		script.Parent.MainFrame.Holder.PercentageDisplay.Text = math.floor(OArmour.Value*10) / 10 .. "/" .. OMaxArmour.Value

		OArmour.Changed:Connect(function()
			script.Parent.MainFrame.Holder.Bar.Size = UDim2.new((OArmour.Value/OMaxArmour.Value) * 1.013, 0,0.663, 0)
			script.Parent.MainFrame.Holder.PercentageDisplay.Text = math.floor(OArmour.Value*10) / 10 .. "/" .. OMaxArmour.Value
		end)
	end
end)

Nope still the bar doesnt respawn when i reset

it stays the same when you reset?

yes it still the same ()(((((((

hmmm does the script output any errors in the console?

No at all it doesnt say any sign of the armor bar gui or the script of it

try to use the code I wrote above with ResetOnSpawn disabled

But which line of code do you want me to put that code?

also shall i use the old script one or the one u gave me fully?

the one I gave you fully should work

Ok so what about the first code that u gave me

where so i put it like which line