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

Help with gamepass giver? (Item given on bought)

Asked by
Qu_xtty -8
3 years ago
local mps = game:GetService("MarketplaceService")
local gamepass_id = 8946545

game.Players.PlayerAdded:Connect(function(player)
    if mps:UserOwnsGamePassAsync(player.UserId, gamepass_id) then
        game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("Backpack")
        game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("StarterGear")
    end
end)

game.ReplicatedStorage.Give.OnServerEvent:Connect(function(player)
    game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("Backpack")
    game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("StarterGear")
end)

I want to make it so that if the gamepass is bought, Lemonaide Bleach will be inside of the players inventory forever. Please help!

2 answers

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

One thing I noticed about your script: You add the item to starter pack. This is not a good idea, as if it decides to actually put it in the starter pack, it will give it to all players on respawn. Instead, you just need make a connect on player reset function that checks if the player that that was just added has the gamepass, then gives the item to them. Heres the fixed script:

wait(2) --Keep at 2 for safety.

local gpid = 3333333333 --Change to your gamepass id

local mps = game:GetService("GamePassService") -- You need the gamepass service, not the marketplace service.
function respawned(char)
    player = game.Players:FindFirstChild(char.Name)
    print("Respawned")
    if char:FindFirstChild("Head") ~= nil then
        print("It's a Player!")
        if GPS:PlayerHasPass(player, gpid) then
            print("Has gamepass")
            game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player.Backpack
        else
            print("No gamepass")
        end
    end
end
game.Workspace.ChildAdded:connect(respawned)
0
where do i put the gamepass id? Qu_xtty -8 — 3y
0
My man there isnt a gampass service CrypxticDoge 135 — 3y
0
because i would think that the script wouldnt know which gamepass you are trying to reference. Qu_xtty -8 — 3y
0
Read my edited answer sergeant_ranger 184 — 3y
0
also, there is a gamepass service sergeant_ranger 184 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
local mps = game:GetService("MarketplaceService")
local gamepass_id = 8946545

game.Players.PlayerAdded:Connect(function(player)
    if mps:UserOwnsGamePassAsync(player.UserId, gamepass_id) then
        game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("Backpack")
plr.CharacterAdded:Connect(function(Character)
        repeat wait() until plr.Character ~= nil    
        local player = game.Players:GetPlayerFromCharacter(Character)
        game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("Backpack")
    end)
end)

Don't put the gear in the StarterPack, instead put it in the backpack when respawning.

Answer this question