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

Help With Gamepasses? (Marketplace Service)

Asked by 9 years ago

I'm testing out a gamepass that gives the player a potato when they buy it.

Currently, it's not working because it says player is nil at line 13.

How can I fix this?

local passId = 264705769 -- change this to your game pass ID.
local potato = game.Lighting:WaitForChild("Potato"):Clone()


function isAuthenticated(player) -- checks to see if the player owns your pass
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) then
        local player = game.Players.LocalPlayer
        print(plr.Name .. " has bought the game pass with id " .. passId)
        potato.Parent = player.Backpack
        potato.Parent = player.StarterGear
    end
end)
0
Why make a variable for the player? you could just say "potato.Parent = plr.Backpack". That's what was passed in the PlayerAdded event. funyun 958 — 9y

3 answers

Log in to vote
9
Answered by 9 years ago

You don't need and you can't declare the player such as "local player = game.Player.LocalPlayer" when you're on a Server Script.And you don't need to declare your player two time, they're the same player.

Your script fix here:

local passId = 264705769 -- change this to your game pass ID.
local potato = game.Lighting:WaitForChild("Potato"):Clone()


function isAuthenticated(player) -- checks to see if the player owns your pass
    return game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) then
        print(plr.Name .. " has bought the game pass with id " .. passId)
        potato.Parent = plr.Backpack
        potato.Parent = plr.StarterGear
    end
end)

Ad
Log in to vote
11
Answered by
rexbit 707 Moderation Voter
9 years ago

LocalPlayer only works if using a LocalScript, The player is already defined by the parameter plr.

local passId = 264705769
local potato = game.Lighting:WaitForChild("Potato"):Clone()


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 the game pass with id " .. passId)
        potato.Parent = plr.Backpack
        potato.Parent = plr.StarterGear
    end
end)

Log in to vote
-3
Answered by 9 years ago

local passId = 264705769 local potato = game.Lighting:WaitForChild("Potato"):Clone()

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 the game pass with id " .. passId) potato.Parent = plr.Backpack potato.Parent = plr.StarterGear end end)

Answer this question