Why does script only work for 1 person?

This is my script, if I join first, it gives me the tool but if someone joins as Shiekh Al Khara after me, it doesn’t give Shiekh Al Khara the tool? Any help?

--// Variables and Services

local GroupId = 6401031		
local CharHide = 0			
local Players = game:GetService("Players")	
local ServerStorage = game:GetService("ServerStorage")	
	
Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = 'leaderstats'
	leaderstats.Parent = player
	
	local Rank = Instance.new("StringValue")
	Rank.Name = 'Rank'
	Rank.Value = 'Guest'
	Rank.Parent = leaderstats
	
	if player:IsInGroup(GroupId) then
		local role = player:GetRoleInGroup(GroupId)
		if string.len(role) <= CharHide then
			warn('[GroupLeaderboard] Attempted to hide more characters than role has; using default name')
			Rank.Value = role
		else
			local role = string.sub(role, CharHide+1)
			Rank.Value = role
		end
	end
	
  	 local function giveAccessCard()
	
	   if player.leaderstats.Rank.Value == "Royal Family" or "Sheikh Al Khara" then

	   local accessCard = ServerStorage:WaitForChild("Tools")["Royal Access Card"]:Clone()
	   accessCard.Parent = player:WaitForChild("Backpack")
        end
end
	player.CharacterAdded:Connect(function(Character)
		 Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	end)
	giveAccessCard()
end)

Is it a local script?
(30characters)

1 Like

No, it’s not. It’s a server script.

You’re writing this statement incorrectly:
if player.leaderstats.Rank.Value == "Royal Family" or "Sheikh Al Khara" then

It does not respect the first value to check. Try rewriting it into:
if player.leaderstats.Rank.Value == "Royal Family" or player.leaderstats.Rank.Value == "Sheikh Al Khara" then


In summary, you’re trying to do if string then.

1 Like

Also, I want the player with THAT rank to receive the tool, not other people. If there is a player with that rank, it will give the tool to others which I don’t want

If you want a player exclusive AND rank, then rewrite it and add statement to check the player’s UserId to match it. If the statement is fulfilled, run the code within the scope.

1 Like

replace

player.CharacterAdded:Connect(function(Character)
		 Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	end)
	giveAccessCard()

with

player.CharacterAdded:Wait()
giveAccessCard()
player.Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
1 Like