I am trying to make a script that gives a piece of gear to the buyer but it’s not working.
local id = 10977515
game.Players.PlayerAdded:connect(function(player)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
game.ReplicatedStorage.M82:Clone().Parent = player:WaitForChild("StarterGear")
end
end)
Here is the script, can you guys see anything wrong with it?
I’m not a amazing programmer, I don’t really know whats wrong with it at the moment. But I’m on mobile and I found this script in one of my documents. It seems to work.
local MarketPlaceService = game:GetService(“MarketplaceService”)
local GamepassID = NUMBER – GAMEPASSID
game.Players.PlayerAdded:Connect(function(player)
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then
game.ServerStorage.ITEMNAME:Clone().Parent = player:WaitForChild(“Backpack”)
game.ServerStorage.ITEMNAME:Clone().Parent = player:WaitForChild(“StarterGear”)
end
end)
Sometimes the character can load before the UserOwnsGamePass is able to return the result, a way to fix this could be to see if the character already exists and if it does, clone it to the backpack as well.
local id = 10977515
local MarketplaceService = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(plr)
if (MarketplaceService:UserOwnsGamePassAsync(plr.UserId,id)) then
game.ReplicatedStorage.M82:Clone().Parent = plr:WaitForChild("StarterGear")
if (plr.Character) then
game.ReplicatedStorage.M82:Clone().Parent = plr:WaitForChild("Backpack")
end
end
end)
If that doesn’t work, here is a gamepass tool giver script I use in my games, and has worked like a charm since the past few months.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
--[[
FORMAT:
{GamepassID,ToolLocation}
]]
local Gamepasses = {
{gamepassid,ToolsReference};
}
local n = #Gamepasses
local c;c = game.Players.PlayerAdded:Connect(function(plr)
for i = 1,n do
local v = Gamepasses[i]
local hasPass
if (v[3]) then
hasPass = v[3](plr)
end
if (not hasPass) then
local s,e = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId,v[1])
end)
if (not s) then
warn("Error checking for gamepass '"..v[1].."' for player '"..plr.Name.."': "..e)
end
end
if (hasPass) then
v[2]:Clone().Parent = plr:WaitForChild("StarterGear")
if (plr.Character) then
v[2]:Clone().Parent = plr:WaitForChild("Backpack")
end
end
end
end)
We’ll need to do some debugging. Put a print statement after every line, and wherever it doesn’t print is where the issue resides. It could be with the MPS line or the tool giving line, but do this just to make sure.
local id = 10977515
game.Players.PlayerAdded:connect(function(player)
print("1")
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
print("2")
game.ReplicatedStorage.M82:Clone().Parent = player:WaitForChild("StarterGear")
end
end)
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
--[[
FORMAT:
{GamepassID,ToolLocation}
]]
local Gamepasses = {
{10977515,game.ServerStorage.M82};
}
local n = #Gamepasses
local c;c = game.Players.PlayerAdded:Connect(function(plr)
for i = 1,n do
local v = Gamepasses[i]
local hasPass
if (v[3]) then
hasPass = v[3](plr)
end
if (not hasPass) then
local s,e = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId,v[1])
end)
if (not s) then
warn("Error checking for gamepass '"..v[1].."' for player '"..plr.Name.."': "..e)
end
end
if (hasPass) then
v[2]:Clone().Parent = plr:WaitForChild("StarterGear")
if (plr.Character) then
v[2]:Clone().Parent = plr:WaitForChild("Backpack")
end
end
end
end)