local function giftHandler()
local function giftPurchaseFinished(player, purchaseID, status)
if status == true then
print(player)
local playerName = game.Players:GetPlayerByUserId(player)
print(playerName.Name)
local playerToGiftId = playerName:FindFirstChild("OtherStats"):FindFirstChild("GiftTo").Value
print(playerToGiftId)
local playerToGift
for i, playerInGame in ipairs(game.Players:GetPlayers()) do
if playerInGame.UserId == playerToGiftId then
playerToGift = playerInGame.Name
print(playerToGift.." Got gifted gamepass")
break
else
print(playerInGame.UserId)
print(playerToGiftId)
print("No")
end
end
if purchaseID == 1241886579 then
print(playerToGift.Name)
if playerToGift.OtherStats then
print("Other Stats")
if playerToGift.OtherStats.Gamepasses then
print("Gamepasses")
end
end
local val = Instance.new("StringValue",playerToGift:FindFirstChild("OtherStats"):FindFirstChild("Gamepasses"))
val.Name = "X2Seeds"
end
playerName:FindFirstChild("OtherStats"):FindFirstChild("GiftsGiven").Value += 1
print("Finished")
end
end
MPS.PromptProductPurchaseFinished:Connect(giftPurchaseFinished)
remotes.GiftRemote.OnServerEvent:Connect(function(playerGifting, playerToGift)
if playerGifting:FindFirstChild("OtherStats"):FindFirstChild("GiftTo") then
local GiftToID = game.Players:GetUserIdFromNameAsync(playerToGift)
playerGifting.OtherStats.GiftTo.Value = GiftToID
end
end)
end
this line is printing nil
print(playerToGift.Name)
This line is erroring because it is nil
cal val = Instance.new("StringValue",playerToGift:FindFirstChild("OtherStats"):FindFirstChild("Gamepasses"))
I dont know why it is nil if it is printing(line 215 in the picture, and this line of code)
print(playerToGift.." Got gifted gamepass")
Is it because it is being changed in the loop?