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

Why is one of my variables indexing as nil?

With the game I'm developing, I'm trying to incorporate a script that can rank someone in my group. The ranking and all works perfectly fine, but when I try inserting my level check, it outputs this error: http://prntscr.com/fzo2a3

What I'd like to know is why the playerLevel variable indexes as nil being that I've used the same methods for the playerLevel variable in other scripts and haven't had an issue.

local group = require(game.ServerScriptService:WaitForChild("GroupFunctions"))
local domain = ""
local key = ""
local groupId = 
local api = group(domain, key, groupId)

game.Players.PlayerAdded:connect(function(player)
	local user = player.UserId
	local playerLevel = game.ReplicatedStorage:FindFirstChild(player.Name.."Level")
	
	if player:IsInGroup(groupId) then
		if player:GetRankInGroup(groupId) >= 1 and player:GetRankInGroup(groupId) < 10 then
			if playerLevel.Value >= 250 and playerLevel.Value <= 499 then
				print(api.setRank(user, 2).message)
			elseif playerLevel.Value >= 500 and playerLevel.Value <= 749 then
				print(api.setRank(user, 3).message)
			elseif playerLevel.Value >= 750 and playerLevel.Value <= 998 then
				print(api.setRank(user, 4).message)
			elseif playerLevel.Value >= 999 then
				print(api.setRank(user, 5).message)
			end
		end
	end
end)

3 comments

0

Does this happen to be stolen code lol....

0

is there supposed to be a space in between the player's name and Level? For example: In you current script, it would look like this: Alpha_ToonLevel when I think you are wanting your script to check for this: Alpha_Toon Level. If so, just add a space before Level inside your string (" Level")

0

@Era_Gamer No, don't know why you think that. @bigboy77584 It's supposed to have no space

1 answer

the only thing I can think of for this is that it trys to find the players level before it is created, what I would recommend to do is local playerLevel = game.ReplicatedStorage:WaitForChild(player.Name.."Level")

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