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