UI won't become visible when I click a TextButton

I want to make it so that the healthbar GUI will show up when the player clicks the “Play” button.

The healthbar doesn’t show when the button is pressed.

I’ve toggled off the “Visible” option of the “Background” UI’s children and I have added it in the script. Still doesn’t work.

Script:

script.Parent.MouseButton1Click:Connect(function()
	game.StarterGui.HealthGui.Background.Visible = true
	game.StarterGui.HealthGui.HealthDisplay.Visible = true
	game.StarterGui.HealthGui.TextLabel.Visible = true
end)
2 Likes

The starterGui shows for everyone… Its the starterGui and it does not update live, but rather what you spawn with! But instead we have the PlayerGui, which is from player to player! Do this instead:

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	player.PlayerGui.HealthGui.Background.Visible = true
	player.PlayerGui.HealthGui.HealthDisplay.Visible = true
	player.PlayerGuii.HealthGui.TextLabel.Visible = true
end)

Hope this helps!

2 Likes

I tried this and it does work, but it doesn’t show again when the player respawns.

Try setting HealthGui’s ResetOnSpawn property to false.

1 Like
local player = game.Players.LocalPlayer
while task.wait(.07) do
	player.PlayerGui.HealthGui.ResetOnSpawn = false
end

script.Parent.MouseButton1Click:Connect(function()
	player.PlayerGui.HealthGui.Background.Visible = true
	player.PlayerGui.HealthGui.HealthDisplay.Visible = true
	player.PlayerGui.HealthGui.TextLabel.Visible = true
end)

Isn’t that simple?

Cant you just do this?

HealthGui = script.Parent.Parent.Parent.HealthGui -- where ever its located

script.Parent.Activated:Connect(function()
HealthGui:WaitForChild("Background").Visible = true
  HealthGui:WaitForChild("HealthDisplay").Visible = true
HealthGui:WaitForChild("TextLabel").Visible = true

end)

Edit: @MasterAnton01 If HealthGui is a ScreenGui, Use Enabled, not Visible

  1. Visible is not a Valid Member of ScreenGui

  2. That way, you don’t have to go out of your way to Enable or Disable everything inside


plr = game.Players.LocalPlayer
HealthGui = plr:WaitForChild("PlayerGui").HealthGui

script.Parent.Activated:Connect(function()
HealthGui.Enabled = true
end)
local player = game:GetService(“Players”).LocalPlayer
local PlayerGui = player:WaitForChild(“PlayerGui”)
script.Parent.MouseButton1Click:Connect(function()
	PlayerGui.HealthGui.Background.Visible = true
	PlayerGui.HealthGui.HealthDisplay.Visible = true
	PlayerGui.HealthGui.TextLabel.Visible = true
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.