I have a gamepass script that fires an event when a part is touched. This event prompts a gamepass to the player that gives extra walkspeed to the player if they buy it. However, when I run my game in Roblox Studio, buy the gamepass, and reset my character, my character no longer has extra walkspeed and the player can buy the gamepass again. Even if I do not reset my character, the gamepass can be bought again.
There was no error in the output window and I've attempted to debug this issue by putting print statements, however, I failed to find any possible code that could've caused this.
Here are my scripts:
DetectGamepassRequest (Located in ServerScriptService) (Script):
> local part = workspace.Part
> local Players = game:GetService("Players")
> local MarketplaceService = game:GetService("MarketplaceService")
> local gamepassId = 74392253
> local ReplicatedStorage = game:GetService("ReplicatedStorage")
> local GamepassEvent = ReplicatedStorage:WaitForChild("GamepassEvent")
>
> part.Touched:Connect(function(otherPart)
> print("1")
> local humanoidCheck = otherPart.Parent:FindFirstChildOfClass("Humanoid")
> local player = Players:GetPlayerFromCharacter(otherPart.Parent)
>
> if humanoidCheck and player then
> print("2")
> GamepassEvent:FireClient(player)
> end
> end)
>
> GamepassEvent.OnServerEvent:Connect(function(player)
> print("3")
> local character = game.Workspace:FindFirstChild(player.Name)
> character.Humanoid.WalkSpeed *= 2
> end)
GamepassHandler (Located in StarterPlayerScripts) (LocalScript):
> local Players = game:GetService("Players")
> local MarketplaceService = game:GetService("MarketplaceService")
> local gamepassId = 74392253
> local ReplicatedStorage = game:GetService("ReplicatedStorage")
> local GamepassEvent = ReplicatedStorage:WaitForChild("GamepassEvent")
> local player = Players.LocalPlayer
>
> GamepassEvent.OnClientEvent:Connect(function()
> print("4")
> local playerUserID = player.UserId
> local hasPass = false
>
> local success, errorMessage = pcall(function()
> hasPass = MarketplaceService:UserOwnsGamePassAsync(playerUserID, gamepassId)
> end)
>
> if hasPass then
> print("5")
> print("Player already owns the gamepass!")
> else
> print("6")
> MarketplaceService:PromptGamePassPurchase(player, gamepassId)
> end
>
> if not success then
> print("7")
> warn("Something went wrong when checking if user "..player.Name.." has the gamepass! "..errorMessage)
> end
> end)
>
> MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(playerWhoPurchased, soldGamePassId, wasPurchaseSuccessful)
> print("8")
> if soldGamePassId == gamepassId and wasPurchaseSuccessful then
> print("9")
> GamepassEvent:FireServer()
> end
> end)
GamepassPerksHandler (Located in ServerScriptService) (Script):
> local Players = game:GetService("Players")
> local MarketplaceService = game:GetService("MarketplaceService")
> local walkSpeedId = 74392253
>
>
> Players.PlayerAdded:Connect(function(player)
> print("10")
> player.CharacterAdded:Connect(function(character)
> print("11")
> local hasPass = false
> local playerUserId = player.UserId
>
> local success, errorMessage = pcall(function()
> hasPass = MarketplaceService:UserOwnsGamePassAsync(playerUserId, walkSpeedId)
> end)
>
> if hasPass then
> print("12")
> character.Humanoid.WalkSpeed *= 2
> elseif character.Humanoid.WalkSpeed > 16 and not hasPass then
> print("13")
> player:Kick("Please stop exploiting the 2x speed gamepass! Reason: Hacking") -- anti cheat (optional)
> end
> end)
> end)
>
As always, thank you for your time and I appreciate any help anyone gives me!

2 comments
No, I only want to buy the game pass only one time.
Well that is not mentionned in the question