Problem with GUI not appearing even tho the output doesn't show any errors

  1. What do you want to achieve? Keep it simple and clear!
    If you click a button, I want the Health, Stamina bar etc. to appear when spawned without it disappearing after 0.5 seconds.

  2. What is the issue?
    The stat bars appear for 0.5 seconds and then randomly disappear.
    GUI Issue

  3. What solutions have you tried so far?
    I asked in a Discord Server and watched YouTube tutorials but I didn’t find anything related to my issue.

local Folder = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("BengalTiger")
local HealthBar = Folder.Health
local StaminaBar = Folder.Stamina

script.Parent.MouseButton1Click:Connect(function()
	HealthBar.Enabled = true
	StaminaBar.Enabled = true
end)

Workspace looks like this:
Screenshot (2012)

3 Likes

And yeah, the ResetOnSpawn property is disabled!

1 Like

can you show all of the scripts in health and stamina?
i need to watch all to check the problem

if you want add me on team create to help you

1 Like

There is probably another script that disables or removes the guis; i suggest you look through your scripts just incase

2 Likes

If you want I can send you the rblx file, If you wanna check it out, ty!
CharacterSelection.rbxl (51,5 KB)

2 Likes

Yeah there might be one, I just haven’t found which it is or if it even is a script

1 Like

I think it’s because they are in a folder, try moving them out of the folder

Also another tip, your GUI is using offset sizing so it looks weird on mobile

1 Like

The thing is, that it should be a character selection and that’s why they’re in a folder because if you click on tiger for instance you will get the healthbar and the hp which are made for the tiger and if you select another animal so on…
And ty because of the offset sizing, I’ll see what I can do. Atm I want it to work on PC only

1 Like

In that case, use a ScreenGUI instead of a folder and make sure to turn off ResetOnSpawn for that too

I tried, it also didn’t work… I don’t think it’s the folder tho

Have you found a solution yet?

i found the error
im trying to fix it

2 Likes

Fixed!
Just replace the “ChangeCharacter” script in ServerScriptService with this script:

local changeEvent = game.ReplicatedStorage:WaitForChild("ChangePlayerCharacter")

local charsFolder = game.ReplicatedStorage:WaitForChild("Characters")

changeEvent.OnServerEvent:Connect(function(player,chosenCharacter)
	if charsFolder:FindFirstChild(chosenCharacter) then
		local newChar = charsFolder:FindFirstChild(chosenCharacter):Clone()
		local plrChar = player.Character

		if newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.HumanoidRootPart
			newChar:SetPrimaryPartCFrame(plrChar.HumanoidRootPart.CFrame)
		elseif newChar:FindFirstChild("Torso") and not newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.Torso
			newChar:SetPrimaryPartCFrame(plrChar.Torso.CFrame)
		end

		if player.Character:FindFirstChild("Animate") then
			local anim = player.Character:FindFirstChild("Animate"):Clone()
			anim.Parent = newChar
		end

		newChar.Name = player.Name
		player.Character = newChar

		local rootPart = newChar:FindFirstChild("HumanoidRootPart") or newChar:FindFirstChild("Torso")
		local plrRoot = player.Character:FindFirstChild("HumanoidRootPart") or player.Character:FindFirstChild("Torso")

		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end

		newChar.Parent = workspace
		
		local Folder = player:WaitForChild("PlayerGui"):WaitForChild("BengalTiger")
		local HealthBar = Folder.Health
		local StaminaBar = Folder.Stamina
		
		HealthBar.Enabled = true
		StaminaBar.Enabled = true
	else
		warn("character doesnt exist or something went wrong.")
	end
end)
2 Likes

Thank you so much!! I was struggling, but thank you that you took the time to solve this <3

2 Likes

Im sorry, i was doing something but i finished and fix your script!

2 Likes

I know you have solved this, but your game revolves around swapping character models, so I thought I’d share what I know.

I suspect the health bar disappears because you changed character models, and the Humanoid killed you, resetting your gui. This isn’t a 0.5 second delay, this is a frame or two. Note that you “fall” like you have been respawned.

In order to swap out character models without this instant kill, you need to enter a model without a Humanoid, then add the Humanoid after the swap.

3 Likes

I tried that and it worked for me, the health bar didn’t dissapear

2 Likes