Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this Health/Name display script not work?

Asked by 10 years ago

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?

0
I updated my answer. The problem was that it was not a local script. NotsoPenguin 705 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

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)


0
NotsoPenguin, your script didn't work. I can't accept your answer. groovydino 2 — 10y
Ad

Answer this question