I’m having an issue - after somebody purchases gamepass for some gear, it wouldn’t give you that gear, even after reset, but it’ll give you the tool only when you rejoin.
How do I make my script to instantly give that gear after purchase, or at least give it after resetting?
local Id = 7195030 -- Put the gamepass id here, it is found in the url and is the number part
local VipPlayers = {""} -- Any person's name put here will get the gamepass for free
local ToolName = {"BoomBox"} -- Put the name of your tool here that MUST be stored in ServerStorage
local function FindPlayer(Plr)
for Num, Pler in pairs(VipPlayers) do
if Pler == Plr then
return true
end
end
end
game.Players.PlayerAdded:connect(function(Player)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Id) or FindPlayer(Player.Name) then
Player.CharacterAdded:Connect(function(character)
for Num, Tool in pairs(ToolName) do
if game:GetService("ServerStorage"):FindFirstChild(Tool) then
game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
end
end
end)
for Num, Tool in pairs(ToolName) do
if Player.Backpack:FindFirstChild(Tool) == nil then
if game:GetService("ServerStorage"):FindFirstChild(Tool) then
game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
end
end
end
end
end)
So basically your script is running only when the player joins the game. You must use MarketPlace.ProcessReceipt for it. You can find further information about it on this wiki page: MarketplaceService | Documentation - Roblox Creator Hub
Also if you have like a GUI that allows people to purchase gamepasses in game, then you might consider creating like a variable within the Player (such as a BoolValue for each gamepass) that is named something like “HasPurchased [gamepass name]” and then when you run your script, check the Player to see if that value is true or not.
I wouldnt do this, it can be easily exploited since its being done on the client, checks for gamepasses should always be done on the server use the process receipt function instead on the server.
Don’t take my word for it as I haven’t done player purchases in a while. My best guess is to fire a RemoteFunction on the server to handle the whole request.
Then have it return the gear if it has succeeded or not. (If the return value is nil, it most likely failed the transaction. If the return value is a gear, it succeeded)