Need help with a script

What I’ve been trying to make is to make a UI visible and kill a player as soon the player reaches 0 or less/negative points in the leaderstats. The purpose is to make the player lose the game when they reach bankruptcy. UI is already in StarterGui and the script is in StarterPlayerScripts. It is also a Local Script. Here’s the script -

local player = game.Players.LocalPlayer
local pointsValue = player:WaitForChild("Balance")

local ui = player.StarterGui.DeathScreen

	if pointsValue.Value < 0 then
		ui.Enabled = true

		local humanoid = player.Character and player.Character:FindFirstChild("Humanoid")
		if humanoid then
			humanoid.Health = 0
		ui.Enabled = false
1 Like

The player’s player gui is player.PlayerGui, not player.StarterGui

So, line 4 should be changed to local ui = player.PlayerGui.DeathScreen

1 Like

Now it says this.

It refers to this
local pointsValue = player:WaitForChild("Balance")

also where is the script supposed to be at and it must be a script or Local Script?

1 Like

If you’re dealing with UI, you should stick to using local scripts. Also what is the error above??


There’s no error beside that and it doesn’t work

1 Like

Have you tried not using Enabled and just have it all enabled.
Then work with Visible from the GUI.Frame …
That’s how I do this kind of stuff.

1 Like

Are you sure that Balance is in the player object itself? Test play the game and go to Players > (your username) and see there.

1 Like