Another script in ServerScriptService runs when the player is added:
local Players = game:GetService("Players")
local Ranks = require(game:GetService("ServerScriptService"):WaitForChild("Ranks"))
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(Character)
local Rank = plr:WaitForChild("Rank") --This exists already from another script
if Ranks.RankValues[plr.Rank.Value][1] <= 4 then --Assume Rank = "Baron"
--Do things
end
end)
end)
The output errors that I am attempting to index nil with number on the line where it says if Ranks.RankValues[plr.Rank.Value][1] <= 4 then.
This error occurs while my Rank value equals “Baron”. It’s a string value just like in the table. The error happens in multiple different scripts while trying to perform similar checks.
According to the module script, Ranks.RankValues[“Baron”][1] SHOULD equal 12, though, not nil? Any ideas as to why this doesn’t get checked properly?
Add some warns to debug. I copied your code and added warns and the creation of the StringValue and it works as intended:
local Players = game:GetService("Players")
local Ranks = require(game:GetService("ServerScriptService"):WaitForChild("Ranks"))
Players.PlayerAdded:Connect(function(plr)
-- FOR DEBUG
local newVal = Instance.new("StringValue")
newVal.Name = "Rank"
newVal.Value = "Baron"
newVal.Parent = plr
plr.CharacterAdded:Connect(function(Character)
local Rank = plr:WaitForChild("Rank") --This exists already from another script
warn("Current Rank Value in player:", Rank.Value)
if Ranks.RankValues[plr.Rank.Value][1] <= 4 then --Assume Rank = "Baron"
--Do things
warn("value in table:", Ranks.RankValues[plr.Rank.Value][1])
end
end)
end)
It wasn’t a typo in the other script, it ended up being some weird long-wound issue with the way I was getting the table, but I did figure it out. Thanks for the help anyways!