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
8 years ago
Edited 8 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.

01local GC = player.Backpack:WaitForChild("GravityCoil",2)
02 
03game.Players.PlayerAdded:Connect(function(player)
04    player.CharacterAdded:Connect(function(character)
05        if marketplaceService:PlayerOwnsAsset(player, gamePassId) then
06            if GC == nil then
07            GravityCoil:Clone().Parent = player.Backpack
08                    end
09            end
10    end)
11end)

1 answer

Log in to vote
0
Answered by 8 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.

01local GAMEPASS_ID = 123
02local marketplaceService = game:GetService("MarketplaceService")
03local gravityCoil = game.ServerStorage.Tools.GravityCoil
04 
05game.Players.PlayerAdded:Connect(function(player)
06    player.CharacterAdded:Connect(function(character)
07        if marketplaceService:PlayerOwnsAsset(player, GAMEPASS_ID) then
08            gravityCoil:Clone().Parent = player.Backpack
09        end
10    end)
11end)

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 — 8y
0
I've tried your way and when it didn't work i tried the script above and still no luck Nogalo 148 — 8y
0
What is wrong? Have you tried using print() statements, breakpoints, or checked the output? Astradant 45 — 8y
Ad

Answer this question