I cannot figure out why my script is not changing the images visibility

I want this script to change the visibility of images of an nametag that is located in the player as soon as he spawns. Example:

local plr = game.Players.LocalPlayer
local chr = plr.Character
local playerstats= plr:WaitForChild(“leaderstats”)
local playerlevel = plrStats:WaitForChild(“level”)

local currentPlayerLevel = playerlevel.Value

playerlevel.Changed:Connect(function()

if currentPlayerLevel >= 10 then
chr.Nametag.Ranks[“Rank10”].Visible = true

elseif currentPlayerLevel >= 5 then

chr.Nametag.Ranks[“Rank5”].Visible = true

elseif currentPlayerLevel >= 0 then

chr.Nametag.Ranks[“Rank0”].Visible = true

end
end)

This is an compressed version of the script, the orginal just has more elseif statements and if I would add them it would just fill up the post. Note that this script works but just once, after that if the player reaches level 20 for example the imagelabel does not become visible. Only when I rejoin the game the imagelabel that is assigned to the Level is visible.

This is my first post since ive so far always came up with an solution but this is giving me an headache. If you need more information please ask and give me feedback if this is an right way to create an topic.


"]

Dont store the value in a variable. Always use the updated one

local plr = game.Players.LocalPlayer
local chr = plr.Character
local playerstats= plr:WaitForChild(“leaderstats”)
local playerlevel = plrStats:WaitForChild(“level”)


playerlevel.Changed:Connect(function(val)

if val >= 10 then
chr.Nametag.Ranks[“Rank10”].Visible = true

elseif val >= 5 then

chr.Nametag.Ranks[“Rank5”].Visible = true

elseif val >= 0 then

chr.Nametag.Ranks[“Rank0”].Visible = true

end
end)
1 Like

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