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)

14 comments
I get an error, "MarketplaceService" in line 1 is an unknown global, and if I add local I get an error on the "." in line 1 saying "Expected identifier when parsing expression, got "."
i edited the script it should work now
It still doesn't work, I don't get any errors but I also don't get the coil when I purchase it.
can you update your script in post with the new script?
I edited my post with all the ways I tried to implement the code
use the second script, where it is outside, and print the all values (player, id and success) and tell me what it prints
It says: GravityCoil is not a valid member of ServerStorage "ServerStorage" I think that was an error I missed
it means that there's no GravityCoil in the ServerStorage
But there is and it's named GravityCoil
that could mean that this script is in LocalScript while it should be in ServerScript
The script I edited (the second one listed in the original post) is in starter GUI, Screen GUI, Image button, Local Script. If I change the local script to a server script it doesn't work.
i'm talking about your third script in your post, it should be in a serverscript in serverscriptservice
It was just in the workspace, but I moved it to serverscriptservice, it still gives me the same error
can you copy the new script and tell me what it prints?