#Why does my player not get item when he buys/owns the gamepass?

76 messages · Page 1 of 1 (latest)

eager rivetBOT
#

studio** You are now Level 1! **studio

fringe jay
#

You didn't set it's parent

Toolclone.Parent = player.Backpack
fringe jay
#

Errors?

wheat glen
#

does it have to do that i am still testing it?

#

like its a test transaction

wheat glen
fringe jay
#

when testing?

#

in this case, the player would have to rejoin

wheat glen
#

but my skip stage button works smh

fringe jay
#

Well, in this case

#

you will have to add a script to give the player the tool when he buys it

wheat glen
fringe jay
fringe jay
wheat glen
#

so u got to rejoin?

fringe jay
#

since it's inside the playeradded

wheat glen
#

ye i get it

#

but how can u give it immediately

fringe jay
#

yeah, unless you make a script to give it to the player when he buys it

wheat glen
fringe jay
#

Yeah thats obvious

#

UserOwnsGamepassAsync

wheat glen
#

so instead i do playerconnect i do playerbuy right?

fringe jay
#

for when the player buys it?

wheat glen
#

ye

eager rivetBOT
#

studio** You are now Level 2! **studio

fringe jay
#

game.MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamepassId, true)
end)

fringe jay
#

you dont need to use owns gamepass

#

waspurchase tells you that

#

if waspurchased then

#

use the variable instead of game.marketplaceservice

wheat glen
#

works

wheat glen
#

but the player keeps it when he rejoined right?

fringe jay
fringe jay
#

and dont forget about the tool.parent part that you missed

wheat glen
wheat glen
fringe jay
#

Connect:function purpose is to execute a function when something happens

wheat glen
fringe jay
#

yes

wheat glen
fringe jay
#

alright

wheat glen
fringe jay
wheat glen
#

@fringe jay my player gets both items when he buys one of these smh

fringe jay
#

That's because you're giving it the tool when the player joins

#

You are new at scripting right?

wheat glen
#

but shouldnt the script only give one item?

#

like i set only one tool as a variable

fringe jay
#

Alright so I'll explain each line of code for you

#
local MarketplaceService = game:GetService("MarketplaceService") -- It's a roblox service variable (marketplace)
local tool = game.ServerStorage.FusionCoil -- the tool variable
local Id = 821962281 -- the tool Id

game.MarketplaceService.PromptGamepassPurchaseFinished:Connect(function(player, Id, wasPurchase) --a function that is called when a purchase is finished

   if wasPurchase then --wasPurchase is true or false, if player bought the item then true, if true then:
local ToolClone = tool:Clone() --clones the tool, so every player can have it
ToolClone.Parent = player.Backpack --ToolClone.Parent set its location, which is the player backpack,
     end 
end)

game.Players.PlayerAdded:Connect(function(player) -- called when a player joins the game

    local ToolClone = tool:Clone() -- clones the tool
    ToolClone.Parent = player.Backpack -- set its parent (location)

end)

#

can you find what's wrong?

wheat glen
#

nah

fringe jay
#

cmon it's really easy to find it

#

in the notes

#

alright so the error is in the playerAdded function, it's giving the tool to the player without checking if it has the gamepass

#
local MarketplaceService = game:GetService("MarketplaceService") 
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local tool = ServerStorage:WaitForChild("FusionCoil")
local Id = 821962281

MarketplaceService.PromptGamepassPurchaseFinished:Connect(function(player, Id, wasPurchase) 
   if wasPurchase then 
local ToolClone = tool:Clone() 
ToolClone.Parent = player.Backpack 
     end 
end)

Players.PlayerAdded:Connect(function(player) 
local OwnItem = MarketplaceService:UserOwnsGamePassAsync(player.UserId, Id)

if OwnItem then
    local ToolClone = tool:Clone() 
    ToolClone.Parent = player.Backpack 
end

end)
fringe jay
#

📜Join my Discord Community if you want scripting help, give feedback, or just hang out:
https://discord.gg/WC6kPu5W5P

DOWNLOAD ROBLOX STUDIO HERE:
https://create.roblox.com/dashboard/creations
(On the left side under "Resources", click on "Download Studio")

My new mission is to have fun teaching everything I know from developing games on Roblo...

▶ Play video
#

beginner scripting tutorial ; )

wheat glen
#

but wait

#

@fringe jay i got more items in the serverstorage and it still gives me all instead mof that one certain item

fringe jay
#

There is probably another script doing that

#

you should watch the tutorial, these errors are really simple to fix

wheat glen
eager rivetBOT
#

studio** You are now Level 3! **studio

wheat glen
#

and if i still dont know it im just asking here again lol