#Why does my player not get item when he buys/owns the gamepass?
76 messages · Page 1 of 1 (latest)
You didn't set it's parent
Toolclone.Parent = player.Backpack
still doesnt work smh
Errors?
nah not really
oh so you're buying it?
when testing?
in this case, the player would have to rejoin
yeee but my robux amount wont get lower
but my skip stage button works smh
Well, in this case
you will have to add a script to give the player the tool when he buys it
but when he buys the gamepass the "userownsgamepassasync" is checking if he got it or not isnt it?
It checks if the player has the gamepass
Also, it only checks if the player joins the game
so u got to rejoin?
since it's inside the playeradded
yeah, unless you make a script to give it to the player when he buys it
but does he still have it if he rejoins?
so instead i do playerconnect i do playerbuy right?
for when the player buys it?
ye
** You are now Level 2! **
game.MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamepassId, true)
end)
what does the red text mean?
you dont need to use owns gamepass
waspurchase tells you that
if waspurchased then
use the variable instead of game.marketplaceservice
works
tysm<3
but the player keeps it when he rejoined right?
you're welcome : )
Well, you'll have to use this one for that
and dont forget about the tool.parent part that you missed
its still in wym?
so just if wasPurchased or ownsgamepass then
This function will only work when the player buys it
Connect:function purpose is to execute a function when something happens
so i do playeradded event again right?
yes
ill try out later
alright
um idk how to test it out since i dont own the gamepass
Try making a gamepass, and replacing the id with it, then test it in the actual game
i got a really bad problem
@fringe jay my player gets both items when he buys one of these smh
That's because you're giving it the tool when the player joins
You are new at scripting right?
ye haha
but shouldnt the script only give one item?
like i set only one tool as a variable
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?
nah
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)
here's the script
📜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...
beginner scripting tutorial ; )
but wait
@fringe jay i got more items in the serverstorage and it still gives me all instead mof that one certain item
There is probably another script doing that
you should watch the tutorial, these errors are really simple to fix
ty ill watch that:)
** You are now Level 3! **
and if i still dont know it im just asking here again lol