I’m trying to make a script that if player purchased a pass it’ll print “hello” (doing this to test it). But if player didn’t purchased the pass, it’ll wants player to buy the pass. But instead all of this, it just give me a error when i click the button.
Error:
The LocalScript inside the button:
local passID = 5941641926
local button = script.Parent
local mps = game:GetService("MarketplaceService")
local plr = game.Players.LocalPlayer
button.MouseButton1Click:Connect(function()
if mps:UserOwnsGamePassAsync(plr.UserId, passID) then
print("yay teh radio is fixed!1!!")
else
mps:PromptGamePassPurchase(plr, passID)
end
end)
So I’ve tried the same script with your gamepass ID and another game’s gamepass. There must be some problem with the ID you’re using or the gamepass since it did work with the other ID. The problem is not in the script so try rechecking your gamepass ID if you typed it in correctly.
local gamepassId = GAMEPASS_ID -- Replace with your Game Pass ID
game.Players.PlayerAdded:Connect(function(player)
-- Check if the player owns the gamepass
local success, hasPass = pcall(function()
return player:HasPass(gamepassId)
end)
if success then
if hasPass then
print(player.Name .. " owns the gamepass!")
-- Grant them the perk, for example, extra health
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.MaxHealth = humanoid.MaxHealth + 50
humanoid.Health = humanoid.MaxHealth
end
else
print(player.Name .. " does not own the gamepass.")
end
else
warn("Failed to check if player has gamepass: " .. tostring(hasPass))
end
end)
local gamepassId = GAMEPASS_ID -- Replace with your Game Pass ID
game.Players.PlayerAdded:Connect(function(player)
local success, hasPass = pcall(function()
return game:GetService("GamePassService"):UserOwnsGamePassAsync(player.UserId, gamepassId)
end)
if success then
if hasPass then
print(player.Name .. " owns the gamepass!")
-- Grant them the perk, for example, extra health
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.MaxHealth = humanoid.MaxHealth + 50
humanoid.Health = humanoid.MaxHealth
end
else
print(player.Name .. " does not own the gamepass.")
end
else
warn("Failed to check if player has gamepass: " .. tostring(hasPass))
end
end)