I have a gamepass that gives the player a gravity coil when they buy it, but they have to rejoin to get it. How do I make it so that they get it right after they purchase it? Here is the script in Workspace that gives them the gear upon joining:
local MarketPlaceService = game:GetService("MarketplaceService") local GamepassID = 55223985 game.Players.PlayerAdded:Connect(function(player) if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("Backpack") game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("StarterGear") end end)
Here is the script that prompts the purchase (I don't know if you will need it):
local button = script.Parent local player = game.Players.LocalPlayer local gamePassId = script.Parent.GamepassId button.MouseButton1Click:connect(function() if player then game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamePassId.Value) end end)
Edit: I tried putting it inside the ends:
local MarketPlaceService = game:GetService("MarketplaceService") local GamepassID = 55223985 -- The Gamepass ID game.Players.PlayerAdded:Connect(function(player) if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("Backpack") game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("StarterGear") game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(player, id, success) if success and id == 55223985 then game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("Backpack") game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("StarterGear") end end) end end)
I tried putting it outside the ends
local MarketPlaceService = game:GetService("MarketplaceService") local GamepassID = 55223985 -- The Gamepass ID game.Players.PlayerAdded:Connect(function(player) if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("Backpack") game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("StarterGear") end end) game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(player, id, success) if success and id == 55223985 then game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("Backpack") game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("StarterGear") end end)
And I tried putting it in and out of this script too:
local button = script.Parent local player = game.Players.LocalPlayer local gamePassId = script.Parent.GamepassId button.MouseButton1Click:connect(function() if player then game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamePassId.Value) end end)
there's something called PromptGamePassPurchaseFinished
, which is an event that fires when a gamepass purchase prompt closes. the success
tells you if the player bought the gamepass successfully, and the id
tells you the gamepass they purchased
just add it to one of your scripts
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(player, id, success) if success and id == 55223985 then game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("Backpack") game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("StarterGear") end end)
This script should be in ServerScriptService as a ServerScript:
local MarketPlaceService = game:GetService("MarketplaceService") local GamepassID = 55223985 -- The Gamepass ID game.Players.PlayerAdded:Connect(function(player) if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("Backpack") game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("StarterGear") end end) game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(player, id, success) local s, r = pcall(function() if success and id == 55223985 then game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("Backpack") game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("StarterGear") end end) if not s then print(r) print(game.ServerStorage:GetChildren()) end end)
Here is a script I use for buying a tool with leaderstats:
player = game.Players.LocalPlayer backpack = player.Backpack local plr = game.Players.LocalPlayer plr:GetMouse().KeyDown:Connect(function(K) if K == "q" then local sword = game.Lighting.Tools.ClassicSword:Clone() ---- change "ClassicSword" to the name of your tool if player.leaderstats.Kills.Value >= 15 then ----- change 10 to the price of your tool and "Money" to whatever you named your Points for leaderboard player.leaderstats.Kills.Value = player.leaderstats.Kills.Value - 15 ----- change 10 to the price of your tool and "Money" to whatever you named your Points for leaderboard sword.Parent = backpack end end end)
I put the tool under lighting in a folder named tools. It moves it to the players backpack. If this is any help, let me know. If not, then idk. I am new to scripting.