Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

loop checking if player has gamepass doesn't work?

Asked by
0msh 333 Moderation Voter
4 years ago
Edited 4 years ago

I'm not sure if I put the loop on the wrong place or something, but I've tried everything and it just doesn't work... I don't have the gamepass and I went into the server side and changed my "XM" value to 2 which should be change back to 1, but it doesn't do that

wait(1)
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 111

game.Players.PlayerAdded:Connect(function(player)
    while wait() do
    local hasPass = false

    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
    end)

    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end
    if hasPass == true then
    player:WaitForChild("leaderstats")
  player:FindFirstChild("Stats").XM.Value = 2
end
    if hasPass == false then -- I've tried else and elseif but they don't work
     player.Stats.XM.Value = 1
    end
end
end)

1 answer

Log in to vote
1
Answered by 4 years ago

You can just do this with an if statement:

local market = game:GetService("MarketPlaceService")

game.Players.PlayerAdded:Connect(function(player)
        wait(5) --letting the player to load in
        if market:UserOwnsGamePassAsync(player.UserId, 111) then
                -- the player has the gamepass
            else
                -- the player doesn't have the gamepass
        end
end)

Insert that code in a SCRIPT inside SERVERSCRIPTSERVICE.

Hope this helped!

Ad

Answer this question