I need to make sure that when the button is pressed, a pet is issued, but the pet is not displayed but gives an error:attempt to index nil with 'WaitForChild' My script:
script.Parent.MouseButton1Click:Connect(function(Player)
local PetInv = Player:WaitForChild("Pets")
PetInv:WaitForChild(1).Value = PetInv:WaitForChild(1).Value +1
end)
Please, help!
I just noticed the wrong part is that you put Player as an argument in .MouseButton1Click, however, it does NOT have any arguments. Here is your script rewritten:
local player = game:GetService("Players").LocalPlayer script.Parent.MouseButton1Click:Connect(function() local PetInv = player:WaitForChild("Pets") PetInv:WaitForChild("1").Value = PetInv:WaitForChild("1").Value + 1 end)
This should definitely work now.
This is a fixed script, put this as a local script, also if the same error is there, it may be that whatever you are trying to call is not defined. Ex. Did you create a item called "Pets" in the player? If not it will say infinte yield possible. Also, if it says nil, then it doesnt exist, so maybe check your capitalization, and make sure you locate everything correctly. Hope this helps!
local Player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() local PetInv = Player:WaitForChild("Pets") PetInv:WaitForChild(1).Value = PetInv:WaitForChild(1).Value +1 end)