Help with PlayerOwnsAsset

So, basically I’m trying to make a script that detects if that person has that Shirt, then it gives them a certain item.

local mps = game:GetService("MarketplaceService")
local shirt_id = 4668393251

 game.Players.PlayerAdded:Connect(function(player)
 if mps:PlayerOwnsAsset(player.UserId, shirt_id) then
  game.ServerStorage.Gun().Parent = player:WaitForChild("Backpack")
  game.ServerStorage.Gun().Parent = player:WaitForChild("StarterGear")
 end
end)


 game.ReplicatedStorage.Give.OnServerEvent:connect(function(player)
 game.ServerStorage.Gun:Clone().Parent = player:WaitForChild("Backpack")
 game.ServerStorage.Gun:Clone().Parent = player:WaitForChild("StarterGear")
end)

line 6 and 7: Gun() should be Gun:Clone()

ok ignore that, but there is something wrong with line 5

It should be a player object, not their UserId.

mps:PlayerOwnsAsset(player, shirt_id)

Edit: If you would like, wrapping your code in a pcall helps prevents errors. Read more about the documentation here:

1 Like

Oh, okay I will try this okay.

that fixed line 5, but now line 12 is broken, it says give is not a valid memeber of replicated storage.

image

Try using WaitForChild

game.ReplicatedStorage:WaitForChild("Give").OnServerEvent:Connect(function(player)

nvm, the error is the gun isn’t being put in my backpack

THANK YOU !!! THIS FIXED MY ISSUE I THOUGHT I WAS GONNA GET BANNED FOR NOT KNOWING, MY PLAYERS DIDINT GET THEIR ITEMS AND ROBLOX THINK I SCAMMED THEMD :smiley:

If your issue is fixed make sure to mark the solution so others can be aware this problem is solved

1 Like