Hello everyone, I have a script that checks whether a player has a gamepass, and changes the player’s kit if they do. The script is as follows:
local PlayerKit = Instance.new("StringValue", Player)
PlayerKit.Name = "PlayerKit"
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserID, 76122957) then -- Explorer
for _,child in pairs(repstore.Explorer:GetChildren()) do
child.Parent = Player.Character
end
PlayerKit.Value = "Explorer"
end
However, I’m wondering whether I need to do pcalls for this script. I’m not familiar with pcalls, but I know that you need to do it sometimes, if the script is very important for gameplay. Thanks!
Does the script work without pcalls?
I think you should use a pcall since it’s grabbing data from Roblox, and if there is an error, the whole script might stop.
Not sure if this will work since I’m kind of new to pcalls too, but try this:
local success, Owns = pcall(function()
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserID, 76122957)
end)
if Owns then
-- do stuff
end
local success, Owns = pcall(function()
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserID, 76122957)
end)
if success then
if Owns then -- owns pass
else -- does not own pass
end
end