Hello, I am currently making an obby, and I’ve made a reset all players gamepass, which resets everyone apart from the person who bought the developer product, for testing purposes, I made it kill the player who bought the devproduct, but nothing happens, I get no errors…
Here is my code:
elseif recieptInfo.ProductId == 959980970 then
local Player = game.Players:GetPlayerByUserId(recieptInfo.PlayerId)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name == Player.Name then
v.leaderstats.Stage.Value = 1
v:LoadCharacter()
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
You have the player indexed already, why are you going through a for loop?
you can just do:
elseif recieptInfo.ProductId == 959980970 then
local Player = game.Players:GetPlayerByUserId(recieptInfo.PlayerId)
Player.leaderstats.Stage.Value = 1
Player:LoadCharacter()
return Enum.ProductPurchaseDecision.PurchaseGranted
Also i realized why your code didnt work with no errors, its because the for loop stopped because of the return line. Just lettin ya know
elseif recieptInfo.ProductId == 959980970 then
local Player = game.Players:GetPlayerByUserId(recieptInfo.PlayerId)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name ~= Player.Name then --if its not the buyer, they will be reset
v.leaderstats.Stage.Value = 1
v:LoadCharacter()
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
firstly, theres no reason for you to check for the players’ names since it will just be the same object
secondly, youre returning on the first loop, your code should rather be
elseif recieptInfo.ProductId == 959980970 then
local Player = game.Players:GetPlayerByUserId(recieptInfo.PlayerId)
for i,v in pairs(game.Players:GetPlayers()) do
if v ~= Player then
v.leaderstats.Stage.Value = 1
v:LoadCharacter()
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end