Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you change a players clothing if they have a gamepass?

Asked by 5 years ago
Edited 5 years ago

So I tried this and it wont work what do I do to fix it?

local MarketplaceService = game:GetService("MarketplaceService")

local Players = game:GetService("Players")

local gamePassID = 0

function onPlayerSpawned(player)

    local hasPass = false

    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
    end)       

    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end

    if hasPass == true then

      local pant = Parent:GetChildren()
      for i=1,#pant do
      if (pant[i].className == "Pants") then
        pant[i].PantsTemplate = "http://www.roblox.com/asset/?id=0"
        end
    end
    local shirt = Parent:GetChildren()
    for i=1,#shirt do
    if (shirt[i].className == "Shirt") then
        shirt[i].ShirtTemplate = "http://www.roblox.com/asset/?id=0"
        end
    end

 end
end

game.Players.PlayerAdded:connect(function(player)
 player.CharacterAdded:connect(function()
   onPlayerSpawned(player)
 end)
end)

Players.PlayerSpawned:Connect(onPlayerSpawned)

P.S you can use the fixed version its not just for me its for everyone!

0
Have you change the Game Pass id and the clothing asset id? Or is this just a example code? RainbowBeastYT 85 — 5y
0
Example. vincentthecat1 199 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

The gamepass will not work if the user has no shirt or pants on (though people usually do). Instead of replacing the ID, you can wait for the clothes in the player, destroy them, and clone the gamepass clothes from (ServerStorage or Lighting or the Script) into the player. Basically, it destroys the player's old clothes and inputs the new clothes instead of changing the ID. Changing the ID does work as well, although if people have no clothes or some clothes, it won't work and you have to add more elements into your script to detect them.

Ad

Answer this question