ServerStorage giving gear is not always working...?

Issue
I have a gamepass menu, after player purchases gamepass it sometimes gives the gear and sometimes not…? Not sure what’s going on or what’s causing this, been trying different things all day and can’t seem to get around it. I’ve tried testing it in studio and in actual game, and can’t determine what’s causing this.
localscript – inside a gui

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local gamepassId = 12913649 -- GamePass ID

local remoteEvent = ReplicatedStorage:WaitForChild("GiveItemEvent")

local function giveItemToPlayer(player)
	remoteEvent:FireServer(player)
end

local player = Players.LocalPlayer

local function onPromptPurchaseFinished(purchased, errorMsg)
	if purchased then
		print("prompt finished, let's check if they purchased")
		if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
			print("Player now owns the GamePass. Item request sent to the server.")
			giveItemToPlayer(player)
		else print "bro still does not have the gamepass"

		end
	else
		print("I have no damn clue what happened", errorMsg)
	end
end

local button = script.Parent
button.MouseButton1Click:Connect(function()
	-- Check if the player already owns the GamePass
	MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptPurchaseFinished)
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
		print("Player already owns the GamePass. Item request sent to the server.")
		giveItemToPlayer(player)
	else
		print("Player does not own the GamePass. Prompting purchase.")
		MarketplaceService:PromptGamePassPurchase(player, gamepassId)
		end
		
end)

ServerScriptService – uses a RemoteEvent: “GiveItemEvent”

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "GiveItemEvent"
remoteEvent.Parent = ReplicatedStorage

local gearName = "SnowmanSword" -- gear

local function giveItemToPlayer(player)
	local character = player.Character or player.CharacterAdded:Wait()

	-- Get the gear from ServerStorage
	local gear = ServerStorage:FindFirstChild(gearName)

	if gear then
		-- Clone the gear and parent it to the player's character
		local gearClone = gear:Clone()
		gearClone.Parent = character

		-- Cloning the gear a second time to save it in StarterGear
		local savedGear = gear:Clone()
		savedGear.Parent = player.StarterGear
	else
		warn("Gear not found in ServerStorage.")
	end
end

remoteEvent.OnServerEvent:Connect(function(player)
	giveItemToPlayer(player)
	print("Item given to player:", player.Name)
end)

I know some of the code might not make sense lmao but just let me know if you need any other information or know what might be causing this, thanks for reading :slight_smile:

Try this

local Players = game:GetService("Players")

local MarketPlaceService = game:GetService("MarketplaceService")

local GamepassID = 666

local ToolName = "toolname here"

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)

nah still no luck, so strange…

It’s probably Roblox glitch, wait until it fixes

As far as I know, you cannot check the purchase status on the client; this can only be done on the server.

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, wasPurchased)
	if wasPurchased then
		-- action
	end
end)

Yeah, that’s why I have a remote event and server script.

try this:
server

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")

local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "GiveItemEvent"
remoteEvent.Parent = ReplicatedStorage

local gearName = "SnowmanSword" -- gear

local function giveItemToPlayer(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local gear = ServerStorage:FindFirstChild(gearName)

	if gear and not player.Backpack:FindFirstChild(gearName) and not character:FindFirstChild(gearName) then
		local gearClone = gear:Clone()
		gearClone.Parent = player.Backpack
		
		character.Humanoid:EquipTool(gear)

		local savedGear = gear:Clone()
		savedGear.Parent = player.StarterGear
	else
		warn("Gear not found in ServerStorage.")
	end
end

remoteEvent.OnServerEvent:Connect(giveItemToPlayer)

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, wasPurchased)
	if wasPurchased and gamePassId == 12913649 then
		giveItemToPlayer(player)
	end
end)

client

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local gamepassId = 12913649 -- GamePass ID

local remoteEvent = ReplicatedStorage:WaitForChild("GiveItemEvent")

local button = script.Parent

local function giveItemToPlayer(player)
	remoteEvent:FireServer(player)
end

local player = Players.LocalPlayer

local function onPromptPurchaseFinished(purchased, errorMsg)
	if purchased then
		print("prompt finished, let's check if they purchased")
		if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
			print("Player now owns the GamePass. Item request sent to the server.")
			giveItemToPlayer(player)
		end
	end
end

button.MouseButton1Click:Connect(function()
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
		giveItemToPlayer(player)
	else
		MarketplaceService:PromptGamePassPurchase(player, gamepassId)
	end
end)
1 Like

You should use .ProcessReceipt instead of :PromptPurchaseFinished.
Check this out if you are confused.

this did the trick! appreciate it! :hearts:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.