Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My gamepass script isn't giving tools?

So i'm trying to make a gamepass give you some tools. Problem is, I can't actually get it to give the tools.

Output log: 18:49:41.123 - Workspace.Script:11: attempt to index global 'Player' (a nil value)

local passId = 363035405 -- change this to your game pass ID.


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
	Weapon = game.Lighting.Grinder:Clone()
Weapon.Parent = Player.Backpack
	end
end)

1 answer

✓ Accepted answer

You used a variable that wasn't defined on line 11 -- "Player". In that function, you have the player parameter set to "plr", so the script should be:

local passId = 363035405 -- change this to your game pass ID.


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
		Weapon = game.Lighting.Grinder:Clone()
		Weapon.Parent = plr.Backpack
	end
end)

Hope this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.