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

How could i save tools awarded with gamepasses after death?[UPDATED]

Asked by
Nogalo 148
7 years ago
Edited 7 years ago

I'm awarding items from gamepasses and everything works except i can't seem to save them after death and rejoining the game.I've tried many different alternatives but to no avial.This script here is my latest attempt to make it work.

Thanks for your time.

local GC = player.Backpack:WaitForChild("GravityCoil",2)

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        if marketplaceService:PlayerOwnsAsset(player, gamePassId) then
            if GC == nil then
            GravityCoil:Clone().Parent = player.Backpack
                    end
            end
    end)
end)

1 answer

Log in to vote
0
Answered by 7 years ago

Well if the players had to buy a gamepass, you don't need to save them or anything, just check if they own the gamepass. We're going to use the PlayerAdded event for this one.

local GAMEPASS_ID = 123
local marketplaceService = game:GetService("MarketplaceService")
local gravityCoil = game.ServerStorage.Tools.GravityCoil

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        if marketplaceService:PlayerOwnsAsset(player, GAMEPASS_ID) then
            gravityCoil:Clone().Parent = player.Backpack
        end
    end)
end)

We don't need to save the GravityCoil inside the player, we can just put it inside of ServerStorage. You can also clone to StarterGear if you'd like. I just chose this way as an easy method of allowing the player to buy the gamepass when they're in-game and still get the coil when they respawn, but there are other ways to do that.

0
Unfortunately it doesn't work and i have no idea why Nogalo 148 — 7y
0
I've tried your way and when it didn't work i tried the script above and still no luck Nogalo 148 — 7y
0
What is wrong? Have you tried using print() statements, breakpoints, or checked the output? Astradant 45 — 7y
Ad

Answer this question