A script that'll add clothes to a player when the player doesn't have a gamepass

this code is supposed to add clothes to a player when the player doesn’t have a gamepass the problems with this are, it’s not showing me any error’s so I don’t know what’s wrong and it doesn’t give the player the clothes when it’s supposed to.
I’ve looked at the “PlayerAdded” and “characterAdded” on the Roblox dev page and looked at some videos on youtube and I Can’t seem to get it working (it’s set to true so i could see if it would give me the clothes and it doesn’t)

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamepass = 13301294

game.Players.PlayerAdded:Connect(function(AdddedPlayer)
	AdddedPlayer.CharacterAdded:Connect(function(Character)
		local succcess, message = pcall(function()
			hasPass = MarketplaceService:UserOwnsGamePassAsync(Players.UserId, gamepass)
		end) 
		if hasPass == true then
			print("alreadyhave")
			if Character:FindFirstChild("Shirt") then
				Character.Shirt = "rbxassetid://594022753"
			else
				Instance.new("Shirt",Character)
				Character.Shirt = "rbxassetid://594022753"
			end
			if Character:FindFirstChild("Pants") then
				Character.Pants = "rbxassetid://129459076"
			else
				Instance.new("Pants",Character)
				Character.Pants = "rbxassetid://129459076"
			end

		end
	end)
end)
3 Likes

You don’t really need to make hasPass a global variable, simply put an if statement which checks if the player has the gamepass, and if he doesn’t, return something:

local success, returned = pcall(function()
    if MarketplaceService:UserOwnsGamePassAsync(Players.UserId, gamepass) then
        return true
    else
        return false
    end
end)

if success and return == false then
    print("Player doesn't have gamepass, overwrite clothings.")
end

But either way, it seems more reasonable to use HumanoidDescriptions. Here is a post which asks further about them: How to change character appearance (Shirt, Pants and Accessories) - Help and Feedback / Scripting Support - Roblox Developer Forum

If you need to access the Developer Hub page of it, simply do a search. (May vary with your searching engine.)

2 Likes

i was wondering if you could explain what i’ll have to do but simplify it