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

Hat Gamepass Script not functioning, why?

Asked by
BryanFehr 133
5 years ago

No errors coming up when ran. The hat goes into the script as a child. Hat is an accessory with handle named 'Accessory'.

local MarketplaceService = game:GetService('MarketplaceService')

local GAMEPASSID = 5885163

local function AddHatToCharacter(Character)

    script:FindFirstChildOfClass('Accessory'):Clone().Parent = Character
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, GamePassId, Purchased)
    if Purchased then
        if GamePassId == GAMEPASSID then 
            Player.CharacterAdded:Connect(function(Character)
                AddHatToCharacter(Character)
            end)

            if Player.Character then
                AddHatToCharacter(Player.Character)
            end
        end
    end
end)

game:GetService('Players').PlayerAdded:Connect(function(Player)
    if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GAMEPASSID) then
        Player.CharacterAdded:Connect(function(Character)
            AddHatToCharacter(Character)
        end)
    end
end)

1 answer

Log in to vote
0
Answered by 5 years ago

First of all you can try putting the accessory inside of ReplicatedStorage and then clone it into the player from there if they have the gamepass:

local Accessory = game:GetService("ReplicatedStorage"):FindFirstChildOfClass("Accessory")
local Market = game:GetService("MarketplaceService")
local GPId = 5885163

local function AddAccessory(Char)
    local clone = Accessory:Clone()
    clone.Parent = Char
end

local function Gamepass_Purchased(Player, PassId, IfPurchased)
    if IfPurchased == true then
        if PassId == GPId then
            if Player.Character ~= nil then
                AddAccessory(Player.Character)
            end
            Player.CharacterAdded:Connect(function(Char)
                AddAccessory(Char)
            end)
        end
    end
end

local function CheckPass(Player, PassId)
    if Market:UserOwnsGamePassAsync(Player.UserId, PassId) then
        repeat wait() until Player.Character ~= nil
        if Player.Character ~= nil then
            AddAccessory(Player.Character)
        end
        Player.CharacterAdded:Connect(function(Char)
            AddAccessory(Char)
        end)
    end
end

Market.PromtGamePassPurchaseFinished:Connect(Gamepass_Purchased)

game.Players.PlayerAdded:Connect(CheckPass)

This should work for you

0
Awesome! It does work, but the hat sits too high on the players head. Why would this be? BryanFehr 133 — 5y
0
this would be the accessories position Protogen_Dev 268 — 5y
0
It doesn't work! I've tried different methods to correspond, but nothing seems to make it work with the accessory in Replicated storage. BryanFehr 133 — 5y
0
try using an already made hat/hair and putting the handle in the accessory of said hat/hair Protogen_Dev 268 — 5y
View all comments (2 more)
0
What do you mean exactly? BryanFehr 133 — 5y
0
If you insert a character model with hair you can use the accessory that hair uses to have an accessory already positioned so that the hair wont float Protogen_Dev 268 — 5y
Ad

Answer this question