Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Putting Gamepass Items into StarterGear? (Unanswered)

Asked by 8 years ago
Edited 8 years ago

So I have some gamepasses that are supposed to give the player an item when they have the gamepass, but it doesn't seem to work on Online mode, but it works perfectly in studio.

What I noticed is that it seems to place the items in the backpack when the player joins, but then it gets removed after he dies, so that led me to believe the code at line 10 only ran the first line after it, and not the others.

I also verified this using :GetChildren() of Startergear and the items were not there.

This is the code:

local passId = 430308264

local potato = game.Lighting:WaitForChild("Jetpack")


function isAuthenticated(player) 
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)
end

game.Players.PlayerAdded:connect(function(plr) -- player is already defined
    if isAuthenticated(plr) then
        print(plr.Name .. " HAS BOUGHT A JETPACK!")
    potato:Clone().Parent = plr.Backpack
        potato:Clone().Parent = plr.StarterGear
    end
end)

Please help, this is urgent.

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

The MarketplaceService won't always work in this case. I suggest using GamePassService, but this will only work in ROBLOX servers, ie; doesn't work in online mode. I have composed a script that should work in your case.

local potato = game.Lighting:WaitForChild("Jetpack")
game.Players.PlayerAdded:connect(function(plr)
    if game:GetService("GamePassService"):PlayerHasPass(plr,430308264) then
        print(plr.Name .. " HAS BOUGHT A JETPACK!")
    potato:Clone().Parent = plr.Backpack
        potato:Clone().Parent = plr.StarterGear
    end
end)

I have tested the script for you, it will give you your "Jetpack" after you die or reset. I hope you learned from this example.

Here are some helpful links you can use to explore further:

http://wiki.roblox.com/index.php?title=API:Class/GamePassService/PlayerHasPass http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService

(I have tried to edit this answer to put in link notations, but it has not work, I apologise for the inconvenience.)

0
GamepassService is outdated an unreliable, so that's why I used MarketplaceService SpazzMan502 133 — 8y
0
Yes, I can agree that it is unreliable; yet I can guarantee this script works in Online Mode; as for I tested it myself. andreagoingblue 0 — 8y
Ad

Answer this question