#Gamepass not given when bought, player has to rejoin

65 messages · Page 1 of 1 (latest)

amber hatch
#

The script:

#

local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassID = 744120513 -- Change this ID to your Gamepass ID
local ToolName = "SuperGravityCoil" -- Change YourToolName to whatever you tool is called

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then
script[ToolName]:Clone().Parent = player.Backpack
end
end)
end)

unkempt pilot
#

All you do is check if the player owns the game pass on entry, so the problem at hand is actually by design

#

You'll need to listen for MarketplaceService.PromptGamePassPurchaseFinished and follow up with its parameters to identify what code to execute when the game pass is bought

amber hatch
#

How would I fix that? I'm very new to scripting I watched a video on this script

indigo sandBOT
#

studio** You are now Level 1! **studio

unkempt pilot
amber hatch
#

Oh

#

Only way they get it is if they reset or rejoin basically if their character respawns

sand yew
#

check every time

unkempt pilot
#

Unfortunately, MarketplaceService:UserOwnsGamePassAsync caches the initial query, so if the game-pass is not owned at the time the player enters the server, it will still be viewed as such until they rejoin

amber hatch
#

Oh

#

I have no idea

unkempt pilot
#

Like I said, solving this is out of your depth as a beginner scripter

#

I can show you what the solution looks like though

#

#448986885570691103

#

@amber hatch

#

So, yeah, as you can see, lol

amber hatch
#

Lol

#

Alot of info

#

Is it possible if I can make it so once bought it respawns the player

#

Because the game is an obby and even if they respawn it will be at a checkpoint

unkempt pilot
#

Absolutely. It would be matter of calling Player:LoadCharacter or killing the player in the game-pass/develop product handler function

amber hatch
#

Uh, a question I dont mind if you say no. Not being rude but is it possible if you can do it?

#

Because I mostly build and scripting isn't my thing as this game is a little project, I got most things working but this is basically the final issue I have

unkempt pilot
#

I'm sorry, no. That code was labour on my part, and I'm not willing to give it away for free

amber hatch
#

Alright, no problem

#

Ill try figure how to repawn them

amber hatch
#

LoadCharacter would be just a reset but quicker?

unkempt pilot
#

Yes

amber hatch
#

Okay

unkempt pilot
#

You can alternatively reduce the objective respawn time to the lowest possible number

amber hatch
#

Thanks alot, I'll let you know how it goes.

unkempt pilot
#

💪

#

Generally, an approach like mine is recommended. Roblox's documentation on MarketplaceService.ProcessReceipt implements the same system, but in a way that isn't good for scalability

amber hatch
unkempt pilot
#

This is something to consider when the 5 second respawn time after falling into the void gets annoying

#

Especially for an obby

indigo sandBOT
#

studio** You are now Level 2! **studio

amber hatch
#

That would be useful if they fall into the void

#

Thanks, this really helps

amber hatch
#

I also used some AI for help

unkempt pilot
sand yew
#

I’m interested

amber hatch
unkempt pilot
# sand yew can you tell me the plot of what you explained?

In order to reduce code duplication, improve scalability and organization, and bypass Roblox's static cache, you would need to centralize game-pass and developer product implementations. You can then load them into a lookup which is devided into two sections for the respective assets and events. It is then a matter of identifying the implementation by its asset ID, as given by the events, and calling its handler function with the associated player. You can build your own ownership cache as the player buys game-passes in-game, and similarly call all game-pass handlers on entry to give what's owed

#

It's not complicated, but it is work

amber hatch
unkempt pilot
#

Why reset the character when they enter the game?

amber hatch
#

Wait what

amber hatch
#

That I shown at first

unkempt pilot
#

No. Your code will run every time the character spawns. If you initiate a re-spawn, the code will enter a never-ending cycle, which will eventually kill the event handler

amber hatch
#

Oh

amber hatch
unkempt pilot
#

You can add individual handlers to MarketplaceService.PromptGamePassPurchaseFinished to run code when the game-pass is bought

#

I'm not sure why a game-pass would need to forcefully respawn the character though, especially when it's a one-time purchase

amber hatch
#

It will be once

#

So they get the gamepass