I was unaware of the Gamepass overhaul that took place just this last April since none of my work had involved GP creation since then. I am now attempting to rewrite my go-to script for GP item distribution, but can’t seem to get it working. For reference, here is an original script in my game that still works thanks to Roblox keeping the old GP system intact for the time being:
Original Script
gpid = 569979204
tools = {“Coal”}
GPS = Game:GetService(“GamePassService”)
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 GPID”)
for i = 1,#tools do
game.ReplicatedStorage:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
end
else
print(“No GPID”)
end
end
end
game.Workspace.ChildAdded:connect(respawned)
Here is my attempt at rewriting it, replacing the GamePassService with the MarketplaceService and running the protocol UserOwnsGamePassAsync instead of PlayerHasPass. As far as I can tell, this should be all that’s necessary; please let me know where I went wrong.
Rewritten Script
gpid = 4641115
tools = {“Bottle”}
GPS = Game:GetService(“MarketplaceService”)
function respawned(char)
player = game.Players:FindFirstChild(char.Name)
print(“Respawned”)
if char:FindFirstChild(“Head”) ~= nil then
print(“It’s a Player!”)
if GPS:UserOwnsGamePassAsync(player, gpid) then
print(“Has GPID”)
for i = 1,#tools do
game.ReplicatedStorage:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
end
else
print(“No GPID”)
end
end
end
game.Workspace.ChildAdded:connect(respawned)
Thank you for your time.