-- the script
local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local char = player.Character
local count = 0
local pets = player.leaderstats.pets
local value = script.Parent.Parent.Value.Value
local notfound = 0
local destroyeds = 0
local value = 0
local function DESTROYY()
print(script.Parent.Name)
print(value)
for i,v in pairs(player.PlayerGui.PetInv.TextButton.Frame.ScrollingFrame.Frames:GetChildren()) do
if v.Name == "UI" then
count = count + 1
print("count")
end
end
if count == 0 then
print("nothing")
else
if count == 1 then
pets.one.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 2 then
pets.two.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 3 then
pets.three.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 4 then
pets.four.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 5 then
pets.five.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 6 then
pets.six.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- and this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
print("destroyed pet")
else
print("not the parent")
notfound = notfound + 1
end
end
end
print("destoyed")
print(count)
end
end
end
end
end
if notfound == 6 then
for i,v in pairs(char.pets:GetChildren()) do
if v.Value.Value <= 0 then
local destroyeds = 0
destroyeds = destroyeds + 1
v:Destroy()
print("notfound is destroyed")
else
print("not notfound")
end
end
print(destroyeds)
destroyeds = 0
notfound = 0
end
end
end
script.Parent.MouseButton1Click:Connect(function()
DESTROYY()
for i,v in pairs(player.PlayerGui.PetInv.TextButton.Frame.ScrollingFrame.Frames:GetChildren()) do
if v.Name ~= "UI" then
if (v.Value.Value) >= value + 1 then
v.Value.Value = v.Value.Value - 1
end
end
end
end)
-- I hope you can fix the problem in this script and thanks for your help
Please hand over the output.
instead of using destroy() use remove()
The first line is already off you just need to do game.Players.LocalPlayer
to get the player assuming this is a local script
the title shows the output Destroy system for pets is attempting to nil with āParentā
can you tell us where the error occurs?
Hi!
I asked for the direct output, since it also tells us which line the error starts at.
Edit: Which is what you asked for in your next message.
hmm yes you got that point. I thinks its cause he is attempting to destroy a nil
This is not a local script so Iām trying to use as much as possible scripts because itās running on the client and hackers/cheaters can hack/change their client and server running scripts are impossible to get for hackers/cheaters. so iām looking for a safer alternative and thatās why iām trying to detect pets with number values
Itās not destroying a nil the if statements have āparentā in it and thatās getting nil for some reason. (Also put some comments in the script to see where it goes wrong).
There is no specific point for the error because itās looping with a count (looks how much pets there are and selecting the right pet āworksā) and in the if statement of the count itās attempting to nil with āparentā
can you show me what it looks like in the explorer?
āv.Value.Valueā is looking kinda buggy, its like taking the property āValueā of an object. Thats why it returns nil cause there is no such thing as Value.Value
here is an example
local valueObj = Instance.new("StringValue")
valueObj.Value = "A Value"
print (valueObj.Value.Value) -- this will print nil since valueObj.Value is "A Value" and youre taking the Value of "A Value" which doesn't exist.
--And i dont think you can put an instance as a Value whether its StringValue, IntValue, or BoolValue
So you might need to rename some objects or something, since i dont know whatās going on really in your problem.
Thanks,
Iāll rename the objects but Iām not really sure of that will fix the problem because itās attempting to nil with āparentā and not with āvalueā.
Why you getting the player like this?
Use this instead
game.Players.PlayerAdded:Connect(function(player)
--all your code
end)
I canāt get the player out of the Index and Iām trying to only use scripts. But I know itās strange and buggy
game.Players.PlayerAdded:Connect(function(player)
-- the script
local char = player.Character
local count = 0
local pets = player.leaderstats.pets
local value = script.Parent.Parent.Value.Value
local notfound = 0
local destroyeds = 0
local value = 0
local function DESTROYY()
print(script.Parent.Name)
print(value)
for i,v in pairs(player.PlayerGui.PetInv.TextButton.Frame.ScrollingFrame.Frames:GetChildren()) do
if v.Name == "UI" then
count = count + 1
print("count")
end
end
if count == 0 then
print("nothing")
else
if count == 1 then
pets.one.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 2 then
pets.two.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 3 then
pets.three.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 4 then
pets.four.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 5 then
pets.five.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
else
print("not the parent")
notfound = notfound + 1
end
end
else
if count == 6 then
pets.six.Value = 0
script.Parent.Parent:Destroy()
for i,v in pairs(char.pets:GetChildren()) do
if (script.Parent.Parent.Value.Value) == v.Value.Value then -- and this is attempting to nil
v:Destroy()
value = (script.Parent.Parent.Value.Value)
print("destroyed pet")
else
print("not the parent")
notfound = notfound + 1
end
end
end
print("destoyed")
print(count)
end
end
end
end
end
if notfound == 6 then
for i,v in pairs(char.pets:GetChildren()) do
if v.Value.Value <= 0 then
local destroyeds = 0
destroyeds = destroyeds + 1
v:Destroy()
print("notfound is destroyed")
else
print("not notfound")
end
end
print(destroyeds)
destroyeds = 0
notfound = 0
end
end
end
script.Parent.MouseButton1Click:Connect(function()
DESTROYY()
for i,v in pairs(player.PlayerGui.PetInv.TextButton.Frame.ScrollingFrame.Frames:GetChildren()) do
if v.Name ~= "UI" then
if (v.Value.Value) >= value + 1 then
v.Value.Value = v.Value.Value - 1
end
end
end
end)
-- I hope you can fix the problem in this script and thanks for your help
end)
Just this
Does playeradded works in a playergui?
You might need to make your code cleaner to avoid more errors and so its easy to read.
But may i see what it looks like in the explorer?
Yeah you can get PlayerGui with that
local playerGui = player:WaitForChild("PlayerGui")
Okay Iāll check it. Thanks for your help!