Works in studio but not in game? Help is needed!

I had made an script that is supposed to give a tool if a player has a certain rank, it only works in studio but not in the actual game. ( I’m using accurate solo play )

No output errors and this is the script.

local function giveAccessCard()

print("true") -- Prints in studio but not in the actual game..

if player.leaderstats.Rank.Value == "Royal Family" or player.leaderstats.Rank.Value == "Sheikh Al Khara" or player.leaderstats.Rank.Value == "Cabinet Ministers" and not player.Backpack:FindFirstChild("Royal Access Card") or player.Character:FindFirstChild("Royal Access Card") then

        local accessCard = ServerStorage:WaitForChild("Tools")["Royal Access Card"]:Clone()

	    accessCard.Parent = player:WaitForChild("Backpack")

        repeat wait(1) until player.Backpack:FindFirstChild("Royal Access Card") or player.Character:FindFirstChild("Royal Access Card")
	
     end
end

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

end)
giveAccessCard()
end) -- I havent showed the full script but this end is for the player added event

Is it a localscript or script? Where is it placed?

Where did you declare the player variable? To make it run for every player, you must use the game.Players.PlayerAdded event.

1 Like

I’m using that and it is a server script placed in server script service but doesn’t work.

Make sure you don’t have any checks, that check if you’re in studio or not.

Edit : Probably you get an error, or the script is broken when joining the game.

1 Like

Can you send the full script please?