Basically, what I’m trying to do is see if the owner of the game has a groupID below or above 50. If they don’t, it prints “No” and if they do, it prints “Yes”. However since GetRankInGroup doesn’t work with UserIDs (specifically the CreatorID) I had to use GetPlayerByUserID. Now when the thing runs, it says attempt to indexnil with GetRankInGroup.
local groupID = 12914986
local ownerID = game.CreatorId
local MinRank = 50
local players = game:GetService("Players")
local plr = players:GetPlayerByUserId(ownerID)
if plr:GetRankInGroup(groupID) >= 50 then
print("No")
elseif plr:GetRankInGroup(groupID) <= 50 then
print("Yes")
end
local groupID = 12914986
local ownerID = game.CreatorId
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
if player.UserId == ownerID then
if player:GetRankInGroup(groupID) >= 50 then
print("Rank greater than or equal to 50.")
elseif player:GetRankInGroup(groupID) < 50 then
print("Rank less than 50.")
end
end
end)
game:GetService("Players") isnt sufficient use GetPlayers
Try using a for loop on the players val.
Instead do:
for i, player in pairs(players:GetPlayers()) do
local plr = player:GetPlayerByUserId(ownerID)
if plr:GetRankInGroup(groupID) >= 50 then
print("No")
elseif plr:GetRankInGroup(groupID) <= 50 then
print("Yes")
end
end
local groupID = 12914986
local players = game:GetService("Players")
local player = players.LocalPlayer
local ownerID = game.CreatorId
if player.UserId == ownerID then
if player:GetRankInGroup(groupID) >= 50 then
print("Rank greater than or equal to 50.")
elseif player:GetRankInGroup(groupID) < 50 then
print("Rank less than 50.")
end
end
I am sure that it requires you to be in game, if you are not in game or the script runs before you load in it will simply error because player instance for “owner” does not exist.
Yeah PlayerAdded doesn’t really work in LocalScript because the LocalScript is loaded after the player is already in game but that’s pretty self explanatory.