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

My gamepass doesn't work when player respawns?

Asked by 3 years ago

The gamepass is supposed to give players a sword. The sword is given but when you die and respawn you don't have it. Here is the script I used on my purchase GUI (it works):

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

local swordGamepassID = 14167811

game.Players.PlayerAdded:Connect(function(player)

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

if hasPass then
    print("player has the gamepass")

    local Sword = game.ReplicatedStorage.FireSword:Clone()
    Sword.Parent = player.Backpack
    end

end)

local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)

if purchaseSuccess == true and purchasedPassID == swordGamepassID then
    print(player.Name .."purchased the game pass!")

    local Sword = game.ReplicatedStorage.FireSword:Clone()
    Sword.Parent = player.Backpack
end

end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)

Here is the script I put in Server Script Service:

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

local swordGamepassID = 14167811

game.Players.PlayerAdded:Connect(function(player)

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

if hasPass then
    print("player has the gamepass")

    local Sword = game.ReplicatedStorage.FireSword:Clone()
    Sword.Parent = player.Backpack
    end

end)

local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)

if purchaseSuccess == true and purchasedPassID == swordGamepassID then
    print(player.Name .."purchased the game pass!")

    local Sword = game.ReplicatedStorage.FireSword:Clone()
    Sword.Parent = player.Backpack
end

end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)

I put the sword inside RepStorage.

0
Okay for some reason the script in the question isn't as i intended it. Hope you can still work it out tho... photo_DracoTEST 12 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

if you want the sword to stay there permenantly, instead of setting up a cloning on respawn system like the above answer suggests, simply clone the sword to the "StarterGear" object and the "Backpack".Roblox automatically clears the backpack and clones "StarterGear" tools to it on player respawn, instead of using:

Sword.Parent = player.Backpack

Use

Sword.Parent = player.StarterGear
local Sword = Sword:Clone()
Sword.Parent = player.Backpack

Above example will clone the sword to the StarterGear, and then re-clone the cloned sword to the backpack

Ad
Log in to vote
0
Answered by 3 years ago

Script is set up so that it runs only when the player joins the game for the first time. Use CharacterAdded to run a function whenever the player respawns.

Answer this question