GUI Frame in server script is not being found when the player dies?

I have a local script that fires a server event to my server script when the player’s health is <= 0, the problem I’m having is my code is saying that the Frame is not being found but I cannot figure out why. I’m using an alt account on my phone and when in-game I’m resetting the player on my phone, which is TedsTestingAcct. What I want to have happen is for the “Dead” text at the top to become visible for the players.

This is a picture of what the Frames look like with their proper names matching the player’s names:
image

This is the code:

Local script:

local function UpdateHealthBar()
	print("Changed")
	local health = math.clamp(Character:WaitForChild('Humanoid').Health / Character:WaitForChild('Humanoid').MaxHealth, 0, 1) --Maths
	local info = TweenInfo.new(Character:WaitForChild('Humanoid').Health / Character:WaitForChild('Humanoid').MaxHealth,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0) --Tween Info
	TweenService:Create(script.Parent:WaitForChild('Juice'),info,{Size = UDim2.fromScale(health, 1)}):Play() -- Create The Tween Then Play It
	
	if Character:WaitForChild('Humanoid').Health >= 0 then
		print(player.Name .. " has died.")
		PlayerDiedRemote:FireServer(player)
	end
end

Server Script:

PlayerDiedRemote.OnServerEvent:Connect(function(player)
	print(player.Name .. " has died.")

	local gameHUD = player:WaitForChild('PlayerGui').MainGame.GameHUD
	local playerGuiElement = gameHUD.Players:FindFirstChild(player.Name)
	
	if gameHUD then
		print("Yes")
	else
		print("No")
	end
	
	if playerGuiElement then
		print("Found GUI element for: " .. player.Name)
		playerGuiElement.Dead.Visible = true
	else
		print("GUI element not found for: " .. player.Name)
	end
end)

This is the output I keep getting:
image

Why is it not finding the GUI Element?

ResetOnSpawn may be enabled, but why don’t you change ui on the client rather than server?

Because I want the UI to be changed for all the players so all players can see that particular player who died have the “Dead” text visible on their player’s card.

Disabling “ResetOnSpawn” still makes the GUI element not found. (edit: I also notice that disabling it makes other GUI not go away when they die, like the in-game UI is meant to be invisible when they go back into the lobby)


image

1 Like

Consider firing a remote to those players and updating the ui on client.

2 Likes

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