Why isn't this script working?

Hey, I’m trying to make a script to determine the best icon to give to a player in my custom leaderboard but it doesn’t work, despite me being in the Owner Module, the value is set to None.
Any ideas?
Thanks.

	local IconToSet = nil
	local adminRanks = {64,71,127,254}
	if Player.MembershipType == Enum.MembershipType.Premium then
		local IconToSet = "Premium"
	elseif Player:IsInGroup(4199740) then
		local IconToSet = "VideoStar"
	elseif table.find(adminRanks,Player:GetRankInGroup(1200769)) then
		local IconToSet = "RobloxAdmin"
	elseif table.find(require(game.ServerScriptService.Modules.LeaderboardRanks["Judicial"]),Player.Name) then
		local IconToSet = "Judicial"
	elseif table.find(require(game.ServerScriptService.Modules.LeaderboardRanks["Upholder"]),Player.Name) then
		local IconToSet = "Upholder"
	elseif table.find(require(game.ServerScriptService.Modules.LeaderboardRanks["InternalSec"]),Player.Name) then
		local IconToSet = "InternalSecurity"
	elseif table.find(require(game.ServerScriptService.Modules.LeaderboardRanks["StaffManager"]),Player.Name) then
		local IconToSet = "StaffManager"
	elseif table.find(require(game.ServerScriptService.Modules.LeaderboardRanks["Developer"]),Player.Name) then
		local IconToSet = "Developer"
	elseif table.find(require(game.ServerScriptService.Modules.LeaderboardRanks["Owner"]),Player.Name) then
		local IconToSet = "Owner"
	end

	local RankValue = Instance.new("StringValue", Player)
	RankValue.Name = "LeaderboardIcon"
	if IconToSet == nil then
		RankValue.Value = "None"
	else
		RankValue.Value = IconToSet
	end
end
1 Like

you’re assigning IconToSet in different scopes than the one you want, remove local from each if statement

this is what you’re doing

local a = nil
if true then
local a = 0
end
print(a) -- output: nil
2 Likes