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

Players lag after they touch a gamepass door that prompts the purchase. Any solutions?

Asked by
xp5u 25
3 years ago
while wait(5) do
local plr = game.Players.LocalPlayer

local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")


local mps = game:GetService("MarketplaceService")

local gamepassID = 18133269


local gamepassOwned = false

pcall(function()

    gamepassOwned = mps:UserOwnsGamePassAsync(plr.UserId, gamepassID)
end)


if gamepassOwned == true then

    workspace.GamepassDoor2.Transparency = 1
    workspace.GamepassDoor2.CanCollide = false
end


humanoid.Touched:Connect(function(touchedPart)

    if gamepassOwned == true then return end


    if touchedPart == workspace.GamepassDoor2 then


        mps:PromptGamePassPurchase(plr, gamepassID)
    end
end)


mps.PromptGamePassPurchaseFinished:Connect(function(playerPurchased, purchasedID, purchaseSuccess)

    if not purchaseSuccess then return end

    if playerPurchased == plr and purchasedID == gamepassID then


        gamepassOwned = true


        workspace.GamepassDoor2.Transparency = 1
        workspace.GamepassDoor2.CanCollide = false
    end
end)
end

It is a localscript in starterplayerscripts

1 answer

Log in to vote
0
Answered by 3 years ago

Its probably due to you are connecting events inside a while loop. If too many events are connected. It would cause lag. Maybe connect the events outside of the while loop?

0
I have already tried it outside the while loop but when the player respawns, the gamepass prompt wont show up xp5u 25 — 3y
0
also can you show me an edited version of the script that has the events outside? I don't know myself. Thanks xp5u 25 — 3y
Ad

Answer this question