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)
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!