StarterGUI TextLabel not changing from ServerScript

I really need some help with a problem that I have been trying to troubleshoot for over a month now. Don’t laugh, I’m new. I have a rebirth button, with a LocalScript, that opens the rebirth menu, determines whether or not the player has enough cash to rebirth and displays the related text. That seems to be working fine.

There are other LocalScripts attached to specific rebirth selection buttons (Health in this example) that fires a ServerScript via RemoteEvent. The ServerScript verifies if the player has enough cash to rebirth, and then increases their rebirth count, increases their health and resets the TextLabel in the Rebirth GUI to show how much cash they need to rebirth again. This is where the problem occurs.

The ServerScript is rebirthing correctly, blanks out their cash, and even displays the correct TextLabel showing how much cash they need to rebirth again. However, it is not disabling the visibility on the “rebirthReady” TextLabel. It’s driving me crazy and again, I’ve tried been troubleshooting it for over a month now. All scripts are below and any help would be GREATLY appreciated.

Please be kind and remember, I’m very new to development. Also - I apologize for the length but wanted to make sure it was all there.

Rebirth Button LocalScript to open Menu (Working)

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local leaderstats = player:WaitForChild("leaderstats")
local pCash = leaderstats:FindFirstChild("Cash")
local pRebirths = leaderstats:FindFirstChild("Rebirths")	

local rebirthMenu = playerGui:WaitForChild("rebirthMenu")
local mainFrame = rebirthMenu:WaitForChild("mainFrame")
local cashLeftMsg = rebirthMenu.mainFrame:WaitForChild("rebirthCashLeft")
local notEnoughCashMsg = rebirthMenu.mainFrame:WaitForChild("notEnoughCash")
local rebirthReadyMsg = rebirthMenu.mainFrame:WaitForChild("rebirthReady")

local panelButton = script.Parent

local cashRebirthStartingValue = 10
local cashRebirthFactor1 = 150
local cashRebirthFactor2 = 0.4
local cashRebirthFactor3 = 15

function rebirthPanelButton()
	
	if rebirthMenu.Enabled == false then
		rebirthMenu.Enabled = true
		if pRebirths.Value == 0 then
			local cashRequired = cashRebirthStartingValue
			if pCash.Value >= cashRequired then
				cashLeftMsg.Visible = false
				notEnoughCashMsg.Visible = false
				rebirthReadyMsg.Visible = true
			else
				notEnoughCashMsg.Visible = false
				rebirthReadyMsg.Visible = false
				cashLeftMsg.Visible = true
				cashLeftMsg.Text = tostring(cashRequired - pCash.Value).." More Cash to Rebirth!"
			end
		else
			
			local cashRequired = (pRebirths.Value * cashRebirthFactor1) / cashRebirthFactor2 + (pRebirths.Value * cashRebirthFactor3)
			
			if pCash.Value >= cashRequired then
				cashLeftMsg.Visible = false
				notEnoughCashMsg.Visible = false
				rebirthReadyMsg.Visible = true
			else
				cashLeftMsg.Visible = true
				notEnoughCashMsg.Visible = false
				rebirthReadyMsg.Visible = false
				cashLeftMsg.Text = tostring(cashRequired - pCash.Value).." More Cash to Rebirth!"
			end
		end
	else
		rebirthMenu.Enabled = false		
	end
end

panelButton.MouseButton1Click:Connect(rebirthPanelButton)

LocalScript to Fire Remote ServerScript (Working)

local repStore = game:GetService("ReplicatedStorage")
local healthEvent = repStore:WaitForChild("rebirthHealthEvent")
local healthButton = script.Parent

healthButton.MouseButton1Click:Connect(function()
	healthEvent:FireServer()
end)

Rebirth ServerScript (Script makes all changes except disabling visibility on rebirthRdyMsg TextLabel)

local repStore = game:GetService("ReplicatedStorage")
local healthEvent = repStore:WaitForChild("rebirthHealthEvent")

local cashRebirthStartingValue = 10
local cashRebirthFactor1 = 150
local cashRebirthFactor2 = 0.4
local cashRebirthFactor3 = 15

local db = true

-- Function Fired when Player Clicks the Health Rebirth Button ------------------------------------------------------------------------------
local function healthButtonPressed(player)
	local leaderstats = player:WaitForChild("leaderstats")
	local pCash = leaderstats:FindFirstChild("Cash")
	local pRebirths = leaderstats:FindFirstChild("Rebirths")

	local playerStats = player:WaitForChild("PlayerStats")	
	local pHealth = playerStats:FindFirstChild("Health")
	local pMaxHealth = playerStats:FindFirstChild("MaxHealth")
	
	local playerGui = player:WaitForChild("PlayerGui")
	local rebirthMenu = playerGui:WaitForChild("rebirthMenu")
	local healthButton = rebirthMenu.mainFrame.buttonFrame:WaitForChild("rebirthHealthButton")
	local cashLeftMsg = rebirthMenu.mainFrame:WaitForChild("rebirthCashLeft")
	local notEnoughCashMsg = rebirthMenu.mainFrame:WaitForChild("notEnoughCash")
	local rebirthReadyMsg = rebirthMenu.mainFrame:WaitForChild("rebirthReady")
	local rebirthHeader = rebirthMenu.mainFrame:WaitForChild("Rebirths")

	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	
	local statsMenu = playerGui:WaitForChild("statsMenu")
	local statPanel = statsMenu:WaitForChild("mainFrame"):WaitForChild("buttonFrame"):WaitForChild("statPanel")
	local healthLabel = statPanel:WaitForChild("healthStat")

	if db then
		if pRebirths.Value == 0 then
			local cashRequired = cashRebirthStartingValue
			if pCash.Value >= cashRequired then
				db = false
				pRebirths.Value = pRebirths.Value + 1
				pCash.Value = 0

				pMaxHealth.Value = pMaxHealth.Value + 10
				humanoid.MaxHealth = humanoid.MaxHealth + 10
				pHealth.Value = pHealth.Value + 10
				humanoid.Health = humanoid.Health + pHealth.Value
				healthLabel.Text = humanoid.Health
				rebirthHeader.Text = "Rebirths: "..tostring(pRebirths.Value)
				
				local cashRequired = (pRebirths.Value * cashRebirthFactor1) / cashRebirthFactor2 + (pRebirths.Value * cashRebirthFactor3)
				cashLeftMsg.Text = tostring(cashRequired - pCash.Value).." More Cash to Rebirth!"
				cashLeftMsg.Visible = true
				notEnoughCashMsg.Visible = false
				rebirthReadyMsg.Visible = false
			else
				cashLeftMsg.Visible = false
				rebirthReadyMsg.Visible = false
				notEnoughCashMsg.Visible = true
				wait(2)
				notEnoughCashMsg.Visible = false
				cashLeftMsg.Visible = true
			end
		else
			local cashRequired = (pRebirths.Value * cashRebirthFactor1) / cashRebirthFactor2 + (pRebirths.Value * cashRebirthFactor3)
			if pCash.Value >= cashRequired then
				db = false
				pRebirths.Value = pRebirths.Value + 1
				pCash.Value = 0
				pMaxHealth.Value = pMaxHealth.Value + 10
				humanoid.MaxHealth = humanoid.MaxHealth + 10
				pHealth.Value = pHealth.Value + 10
				humanoid.Health = humanoid.Health + 10
				healthLabel.Text = humanoid.Health
				rebirthHeader.Text = "Rebirths: "..tostring(pRebirths.Value)
				
				local cashRequired = (pRebirths.Value * cashRebirthFactor1) / cashRebirthFactor2 + (pRebirths.Value * cashRebirthFactor3)
				cashLeftMsg.Text = tostring(cashRequired - pCash.Value).." More Cash to Rebirth!"
				cashLeftMsg.Visible = true
				notEnoughCashMsg.Visible = false
				rebirthReadyMsg.Visible = false
			else
				rebirthReadyMsg.Visible = false				
				cashLeftMsg.Visible = false
				notEnoughCashMsg.Visible = true
				wait(2)
				notEnoughCashMsg.Visible = false
				cashLeftMsg.Visible = true
			end
		end
		wait(0.5)
		db = true
	else
		wait(0.5)
		db = true
	end
end

healthEvent.OnServerEvent:Connect(healthButtonPressed)
1 Like

You mention that the rebirthReadyMsg TextLabel visibility doesn’t get disabled, but does this happen to any other TextLabel? Have you checked the Explorer tab (in game) to find that specific TextLabel to see if the Visibility changes (from the properties tab)? Have you made sure that there isn’t any other script that could be keeping this specific TextLabel visible?

One suggestion I have is to make the visibility changes on the client rather than on the server, as the server shouldn’t actually be the one changing properties to the UI elements. You can do this by firing another RemoteEvent to that specific player, and disable visibility of the TextLabel in a LocalScript.

2 Likes

yeah ima stop quoting.
I agree with @BabyNinjaTime in that you can’t edit the player’s gui from a Script. You need to find stuff to signal when and what to change in the player gui. All references to the player gui should be in a LocalScript.

2 Likes

If the leaderstat values are objects like NumberValue or IntValue
Then I recommend using the .Changed event in a LocalScript.

2 Likes

Thank you guys so much. I’m going to code up the client side local scripts tomorrow. Seriously, cannot thank you enough!

1 Like

If you want a better code, this should do the trick:

local player = game.Players.LocalPlayer
local playerGui = player:FindFirstChild("PlayerGui")
if not playerGui then return end

local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then return end
local pCash = leaderstats:FindFirstChild("Cash")
local pRebirths = leaderstats:FindFirstChild("Rebirths")

local rebirthMenu = playerGui:FindFirstChild("rebirthMenu")
if not rebirthMenu then return end
local mainFrame = rebirthMenu:FindFirstChild("mainFrame")
if not mainFrame then return end
local cashLeftMsg = rebirthMenu.mainFrame:FindFirstChild("rebirthCashLeft")
local notEnoughCashMsg = rebirthMenu.mainFrame:FindFirstChild("notEnoughCash")
local rebirthReadyMsg = rebirthMenu.mainFrame:FindFirstChild("rebirthReady")

local panelButton = script.Parent

local cashRebirthStartingValue = 10
local cashRebirthFactor1 = 150
local cashRebirthFactor2 = 0.4
local cashRebirthFactor3 = 15

function rebirthPanelButton()
	if not pCash or not pRebirths then return end
	if not cashLeftMsg or not notEnoughCashMsg or not rebirthReadyMsg then return end

	if not rebirthMenu.Enabled then
		rebirthMenu.Enabled = true
		if pRebirths.Value == 0 then
			local cashRequired = cashRebirthStartingValue
			if pCash.Value >= cashRequired then
				cashLeftMsg.Visible = false
				notEnoughCashMsg.Visible = false
				rebirthReadyMsg.Visible = true
			else
				notEnoughCashMsg.Visible = false
				rebirthReadyMsg.Visible = false
		

2 Likes

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