Error in script!

checkRegen is not defined in the correct scope. You should either move it outside of the PlayerAdded or move the Connect inside the PlayerAdded.

These replies hurt my brain, you defined the function inside a function so it’s trying to connect nil, also your code does nothing because you never call the function

This should work

system = script.Parent

model = system.Box --

backup = model:Clone()

regen = system.Regen

local gamepassId = 148181594
local market = game:GetService("MarketplaceService")

local function checkRegen(plr)
    if regen.Value == 1 then

        if market:UserOwnsGamePassAsync(plr.UserId,gamepassId) then

            wait(1)

            model = backup:Clone()

            model.Parent = system

            model:MakeJoints()
            
        else
            market:PromptGamePassPurchase(plr, gamepassId)
        end

    end
end

game.Players.PlayerAdded:Connect(function(plr)

	-- This code doesn't actually do anything, BTW, you're never calling checkRegen
    -- I'll call it here for simplicity

    -- checkRegen(plr)
	
end)

-- Also, this code doesn't work, how about I just rewrite it
--regen.Changed:Connect(checkRegen)

regen.Changed:Connect(function()
    for i,v in next, game:GetService("Players"):GetPlayers() do
        checkRegen(v)
    end
end)
1 Like

Basically the checkRegen() function is created it in the PlayerAdded Event function once the script done with player add event function it gonna get out of scop and you Connecting regen.Changed to a nil value the fix for this issue is by removing the checkRegen() function out side the player add event funtion

Ikr. Flagging each response as its Solution Farming

2 Likes

Nope, also, that script should be working 100%, tested it by myself.

Ah yes, my favorite player character, the system variable.

At least test stuff if you’re going to claim you tested it lol

1 Like

line 16 gives an error this one

MarketplaceService:PromptGamePassPurchase() player should be of type Player

The error you’re getting on line 16 is because you’re passing the plr variable as the first argument to the PromptGamePassPurchase() method, which expects a Player object.

To fix this, change plr to plr.UserId in the PromptGamePassPurchase() method call, like this:

game:GetService("MarketplaceService"):PromptGamePassPurchase(plr.UserId, 148181594)

This will pass the player’s UserId as the first argument, which is the correct type expected by the method.


Thats crazy bro :skull:

1 Like

so whats the problem then?____

The code he sent was generated by an AI and is entirely false, use the one I posted and it should work.

1 Like

I think it works but I dont know how to test it because I tried it in 2 player test but then it will just pop up everytime even if I buy it but do you know a way how to test it?

When you click the buy button on a purchase prompt in roblox studio, it doesn’t actually give you the item or remove your robux. You might try testing it in-game or try changing the ownership check to “if game.RunService:IsStudio() then”, as this will always return “true” if you’re currently doing a playtest in roblox studio.

but how can I then test while I buy the item and then I get it I dint have it before and then after that it will say that I own it other wise I cant test it properly

Sorry for bumping the topic, but Put the connection inside game.Players.PlayerAdded, and please test it inside the game, in studio, you’re not actually buying the item, go to the game outside of studio and you should be able to test the code