Why wont my gamepass save?

This is my script and for some reason the gamepass wont save, can someone please fix 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)
local player = game.Players.LocalPlayer
local ownsGamepass = game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(player.UserId,38706262) ------ Your Gamepass ID here

	if ownsGamepass then
		local sword = game:GetService("ReplicatedStorage"):WaitForChild("SpeedCoil"):Clone() -------- Change "ClassicSword" to your tool's name
		sword.Parent = player.Backpack
	end
end

end)

1 Like

Wrong topic use #help-and-feedback:scripting-support

sorry i just got accepted i didnt realise

Something like this may work.

local Button = script.Parent
local gamePassId = script.Parent.GamepassId

local Tool = game:GetService("ReplicatedStorage"):WaitForChild("SpeedCoil")
local MarketplaceService = game:GetService("MarketplaceService")
local Player = game:GetService("Players").LocalPlayer

Button.MouseButton1Click:connect(function()
	if Player then
		local ownsGamepass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamePassId.Value)

		if ownsGamepass then
			Tool:Clone().Parent = Player.Backpack 
			Tool:Clone().Parent = Player.StarterGear
		else
			MarketplaceService:PromptGamePassPurchase(Player, gamePassId.Value)
		end
	end
end)

What do you mean by “The gamepass wont save”?

it wont save when you die since im making an obby game

where would i put the gamepass id though :thinking:

I suggest you add it by PlayerAdded in a ServerScript;

local gamePassId = --gamepassid

local Tool = game:GetService("ReplicatedStorage"):WaitForChild("SpeedCoil")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
       Players.CharacterAdded:Connect(function(Char)
	if Player then
		local ownsGamepass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamePassId.Value)

		if ownsGamepass then
			Tool:Clone().Parent = Player.Backpack 
			Tool:Clone().Parent = Player.StarterGear
		else
			MarketplaceService:PromptGamePassPurchase(Player, gamePassId.Value)
		end
	end
      end)
end)
1 Like

hmm i still cant figure it out

You could try this.

local Button = script.Parent
local gamePassId = 38706262 -- Your gamepass id

local Tool = game:GetService("ReplicatedStorage"):WaitForChild("SpeedCoil")
local MarketplaceService = game:GetService("MarketplaceService")
local Player = game:GetService("Players").LocalPlayer

Button.MouseButton1Click:connect(function()
	if Player then
		local ownsGamepass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamePassId)

		if ownsGamepass then
			Tool:Clone().Parent = Player.Backpack 
			Tool:Clone().Parent = Player.StarterGear
		else
			MarketplaceService:PromptGamePassPurchase(Player, gamePassId)
		end
	end
end)

Are there any errors in the output?

it does get bought but because im making an obby game and i die it doesnt save

it just says that its been enabled 19:29:46.720 enabled: - Client - LocalScript:29
19:31:49.135 enabled - Client - LocalScript:29

basically i need a datastore for it

You should not need to use Data Stores if you are using game passes.

No, you don’t. And what do you mean by not save? You buy the game pass from the game’s store and when you die in the game you lose it?

1 Like

Do you mean like buy the game pass that gives you the item but when you die the item disappears from your inventory and you can’t get it back?

yes i can’t figure it out i’m struggling to figure out what the problem is

robloxapp-20230324-1812240.wmv (3.1 MB)
This is what happens…

ok so exactly what i said…

i think i have a solution:

put this in ServerScriptService

local MarketplaceSvc = game:GetService("MarketplaceService")
local GamepassId = 0 --put your gamepass id here

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(model)
		if MarketplaceSvc:UserOwnsGamePassAsync(plr.UserId, GamepassId) then
			local sword = game:GetService("ReplicatedStorage"):WaitForChild("SpeedCoil"):Clone() -- Change "ClassicSword" to your tool's name
			sword.Parent = plr.Backpack
		end
	end)
end)

tell me if there are errors

TYSM IT ACTUALLY WORKED I really appreciate you all for trying!

Nice! You should mark a reply or even yours as the solution on this post.