I was using TheDevKing’s tutorial on how to make a gamepassshopGUI however the issue is that the script doesn’t give the tool to the player for some reason even if I have the gamepass.
local MarketplaceSerivice = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ToolGamepassId = 16269994
game.Players.PlayerAdded:Connect(function(player)
local Success, message = pcall(function()
hasPass = MarketplaceSerivice:UserOwnsGamePassAsync(player.UserId, ToolGamepassId)
end)
if hasPass then
print("Player Has Gamepass")
local Tool = game.ReplicatedStorage.RedNeonStick:Clone()
Tool.Parent = player.Backpack
end
end)
local function onPromptGamePassPurcahseFinised(player, purchasedPassId, purchaseSuccess)
if purchaseSuccess == true and purchasedPassId == ToolGamepassId then
print(player.Name .. "purchased the gamepass!")
local Tool = game.ReplicatedStorage.RedNeonStick:Clone()
Tool.Parent = player.Backpack
end
end
MarketplaceSerivice.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurcahseFinised)
I think I see why now, your hasPass variable is local to the pcall, I think, try putting a variale declartion beforehand?
local hasPass
local Success, message = pcall(function()
hasPass = MarketplaceSerivice:UserOwnsGamePassAsync(player.UserId, ToolGamepassId)
end)
if hasPass then
print("Player Has Gamepass")
local Tool = game.ReplicatedStorage.RedNeonStick:Clone()
Tool.Parent = player.Backpack
end
I think it could be that you added the tool to the backpack, the character gets added and requests all the tools in StarterGear, there was nothing, so no tools to give.
Oh and I recommend also parenting a tool into StarterGear so they’ll also have the tool when they respawn, so just change this
local Tool = game.ReplicatedStorage.RedNeonStick:Clone()
Tool.Parent = player.Backpack
To this
local Tool = game.ReplicatedStorage.RedNeonStick
Tool:Clone().Parent = player.Backpack
Tool:Clone().Parent = player.StarterGear
If you have anymore issues don’t be afraid to make another post!
One quick question, How would I go about looping through multiple tool gamepasses and then giving players the specific tools if they have the gamepasses for it.
What I did is have a folder in serverstorage with the gamepass tools in it, then in those tools, I add an Attribute called “GamepassId”, and in that attribute, I add in the gamepass Id of the gamepass that gives that tool if you own it,
Then in the code, when a player joins, I loop through the folder, check if they own the gamepass with the id mentioned in the attribute, clone the tool twice and put one in backpack and one in startergear
local MarketplaceSerivice = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local SS = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
for i,v in pairs(SS.GamepassTools:GetChildren()) do
local hasPass
local Success, message = pcall(function()
hasPass = MarketplaceSerivice:UserOwnsGamePassAsync(player.UserId, v.GamepassId)
end)
if hasPass then
print("Player Has Gamepass")
local Tool = v
Tool:Clone().Parent = player.Backpack
Tool:Clone().Parent = player.StarterGear
end
end
end)
I tried this and for some reason it’s not working D: please help lol