Gamepass problem

Hello devforum members

I made a few gamepass’ and used these scripts to make it so that when players buy the gamepass while in game, they obtain the items that comes with it while playing.

The problem with the script is that instead of only giving the items that are supposed to come with the specific gamepass, it gives the player the items of every other gamepass as well. I tested it out and it happens with every gamepass I use it for even if I try to put the tools in a folder to try and specifically only take the weapons from that folder.

Here are the scripts I used:

In the GUI section:

local mps = game:GetService("MarketplaceService")

local gamepass_id = 0

script.Parent.MouseButton1Click:connect(function()

local player = game.Players.LocalPlayer

mps:PromptGamePassPurchase(player, gamepass_id)

end)

mps.PromptGamePassPurchaseFinished:connect(function(player, id, purchased)

if id == gamepass_id and purchased then

game.ReplicatedStorage.Give:FireServer()

end

end)

in the SeverScriptService section:

local mps = game:GetService("MarketplaceService")
local gamepass_id = 0

game.Players.PlayerAdded:Connect(function(player)
 if mps:UserOwnsGamePassAsync(player.UserId, gamepass_id) then
  game.ServerStorage.speedcoil.AccelerationCoil:Clone().Parent = player:WaitForChild("Backpack")
  game.ServerStorage.speedcoil.AccelerationCoil:Clone().Parent = player:WaitForChild("StarterGear")
 end
end)


game.ReplicatedStorage.Give.OnServerEvent:connect(function(player)
 game.ServerStorage.speedcoil.AccelerationCoil:Clone().Parent = player:WaitForChild("Backpack")
 game.ServerStorage.speedcoil.AccelerationCoil:Clone().Parent = player:WaitForChild("StarterGear")
end)

Are you using the same script for your game passes? I also want to highlight something in your code:

This shouldn’t be done the client - the RemoteEvent you are using is exploitable, so exploiters can fire the event on their client and they’ll get the items easily. I’d advise against this, and this should be done the server without the RemoteEvent

1 Like

Okay, so I think the problem is that you are using one remote event for all of your game passes. Therefore, if I buy something it fires than event, and then ALL the server scripts give you the items because they all registered that event as being fired. To fix this you could make multiple events, however I instead recommend you pass a value through the remote event. This could be as simple as “gamepaseName.” Then do a series of if statements saying if it’s this name, give these tools, etc.

To further improve the security of this I recommend you change the event to the button being clicked, and then in the server prompt the purchase and do the rest. This way hackers cannot send the event saying they bought it (giving them the items).

If you have further questions feel free to reach out and I can do my best to help. :slight_smile:

1 Like

Ok thanks for the reply, Im not sure if I can fix it tho because i’m still very new to scripting but ill try.

Thank you, ill try out what you said and make sure to come to you when I get stuck
thanks for the help.

No worries :grin:. Do you have discord? If you would like, I could help you further in DMs if you get stuck.

My discord is totoro987123#4259