Hello, im trying to ake my own gamepass tool script, but when i tried, it gave me the error in the title.
Code
local id = "11561701"
local mps = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)
if mps:UserOwnsGamePassAsync(player,id) then
game.Lighting.butterscotchPie:Clone().Parent = player.Backpack
end
end)
The first argument is the userId of the player and you’re supplying it with the player object itself. Try this instead.
local id = 11561701
local mps = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)
if mps:UserOwnsGamePassAsync(player.UserId, id) then
game.Lighting.butterscotchPie:Clone().Parent = player.Backpack
end
end)
If you want to give the player a tool each time they spawn in then you need to use the CharacterAdded event. Also use ServerStorage or ReplicatedStorage instead of lighting.
local id = 11561701
local mps = game:GetService("MarketplaceService")
function OnPlayerAdded(player)
local function OnCharacterAdded(char)
if mps:UserOwnsGamePassAsync(player.UserId, id) then
game.Lighting:WaitForChild("butterscotchPie"):Clone().Parent = player.Backpack;
end
end
OnCharacterAdded(player.Character or player.CharacterAdded:Wait());
player.CharacterAdded:Connect(OnCharacterAdded);
end
for i,v in ipairs(game.Players:GetPlayers()) do OnPlayerAdded(v) end
game.Players.PlayerAdded:Connect(OnPlayerAdded);