Hey guys I’m new to scripting and have been having some issues with my GamePass script. If anyone could lend a hand I would highly appreciate it!
-
What do you want to achieve? Upon purchasing the gamepass, the tool goes into the player’s inventory and remains there even after death. Also the player should still have the tool after rejoining the game.
-
What is the issue? The tool disappears from the inventory upon death, and doesn’t appear after rejoining the game either.
-
What solutions have you tried so far? Already tried several things, but nothing seems to work.
Here is my code:
local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gpIDs = {
00000001, -- gravity
00000002, -- balloon
00000003, -- grapple
00000004, -- rainbow
00000005, -- boombox
00000006, -- fusion
00000007, -- speed
}
local rewards = {
game.ServerStorage.GravityCoil,
game.ServerStorage.GreenBalloon,
game.ServerStorage.GrappleHook,
game.ServerStorage.RainbowMagicCarpet,
game.ServerStorage.BoomBox,
game.ServerStorage.FusionCoil,
game.ServerStorage.SpeedCoil
}
game.Players.PlayerAdded:Connect(function(player)
for index, pass in ipairs(gpIDs) do
local success, message = pcall(function()
hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserID, pass)
end)
if hasPass then
print("player has the game pass")
local tool = rewards[index]:Clone()
tool.Parent = player.Backpack
tool.Parent = player.StarterGear
else
print("gear obtained")
end
end
end)
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess then
for index, pass in ipairs(gpIDs) do
if purchasedPassID == pass then
print(player.Name .. " purchased item.")
local tool = rewards[index]:Clone()
tool.Parent = player.Backpack
end
end
end
end
MarketPlaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
Also any suggestions on how to improve the code are appreciated! Thanks!