Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this Health/Name display script not work?

I have a script to change the settings of the Health/Name display of a character.

I tested it with two people, but it didn't work.

Here is the script:

HealthShown = false
NameShown = true
function name(plr)
	
	if NameShown == true then
plr.NameDisplayDistance = 100
	if NameShown == false then
plr.NameDisplayDistance = 0
end
	end
end
game.Players.PlayerAdded:connect(name)

function health(player)
	if  HealthShown == true then
player.HealthDisplayDistance = 100
	if HealthShown == false then
player.HealthDisplayDistance = 0
end
	end
end
game.Players.PlayerAdded:connect(health)

What makes this not work?

1 comment

0

I updated my answer. The problem was that it was not a local script.

1 answer

Your if statements have the end in the wrong place. In order for HealthShown==false to be checked HealthShown must have already been true. To fix this we can move the end or change it to an else and remove the end. Also you do not need the == true . Finally there is no reason to have multiple event connections.

This is a localscript make sure to Place it in StarterGui.

HealthShown = false
NameShown = true

function name(plr)
    if NameShown then
        plr.NameDisplayDistance = 100
    else
        plr.NameDisplayDistance = 0
    end
end

function health(player)
    if  HealthShown then
        player.HealthDisplayDistance = 100
    else 
        player.HealthDisplayDistance = 0
    end
name(player)
end

wait(0)
health(Game.Players.LocalPlayer)


1 comment

0

NotsoPenguin, your script didn't work. I can't accept your answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.