Use the previous code but change it up a bit to count only when a desired pet exists (the instances MUST be exact with this code):
local Items = 0
local ItemHolder = workspace
local Reference = workspace.Pet
while task.wait(1) do
Items = 0
for _, Item in pairs(ItemHolder:GetChildren()) do
if Item == Reference then Items += 1 end
end
end
Edit: If you want to go off names, use this code instead (doesnt have to be exact, but must have the same name):
local Items = 0
local ItemHolder = workspace
local Reference = workspace.Pet
while task.wait(1) do
Items = 0
for _, Item in pairs(ItemHolder:GetChildren()) do
if Item.Name == Reference.Name then Items += 1 end
end
end
Main Script: – Basically the datastore (Server Script)
local dss = game:GetService("DataStoreService")
local save = dss:GetDataStore("ExistsValue")
for i, ExistsValue in pairs(game.ReplicatedStorage.Pets_Folder:GetChildren()) do
local Exists = ExistsValue:FindFirstChild("Exists")
game:BindToClose(function()
save:SetAsync("ExistsValue", Exists.Value)
end)
while wait(math.random(5, 10)) do
save:SetAsync("ExistsValue", Exists.Value)
end
local saveddata = save:GetAsync("ExistsValue", Exists.Value)
Exists.Value = saveddata
print(Exists.Value.." exists of "..ExistsValue)
end
The script that gets the number of how much a pet exists: - Local Script
local Index = script.Parent:WaitForChild("Index")
local InfoFrame = Index:WaitForChild("Info")
local PetImage = InfoFrame:WaitForChild("Image"):WaitForChild("PetImage")
local PetName = InfoFrame:WaitForChild("PetName")
local Description = InfoFrame:WaitForChild("Description")
local scrollingFrame = Index:WaitForChild("ScrollingFrame")
local template = scrollingFrame:WaitForChild("Template")
local Pets = RS:WaitForChild("Pets_Folder")
local Click = script.Parent:WaitForChild("Click")
local Difficulty = InfoFrame:WaitForChild("Difficulty")
local plr = game:GetService("Players").LocalPlayer
local Remote2 = game.ReplicatedStorage.GetPetExistsValue
local selectedTemplate = nil
local function selectTemplate(temp)
InfoFrame.Visible = true
selectedTemplate = template
PetImage.Image = temp.PetImage.Image
PetName.Text = "Pet Name: "..temp.Name
Description.Text = RS:FindFirstChild("Pets_Folder"):WaitForChild(temp.Name).Description.Value
Difficulty.Difficulty.Text = "Difficulty: "..RS:FindFirstChild("Pets_Folder"):WaitForChild(temp.Name).Difficulty.Value
InfoFrame.Exists.Text = Remote2:InvokeServer(temp.Name).." Exists" --Here's where I get the number of how much of a pet exists
if RS:FindFirstChild("Pets_Folder"):WaitForChild(temp.Name).Difficulty.Value == "Exclusive" then
Difficulty.ExclusiveGradient.Enabled = true
Difficulty.BackgroundTransparency = 0
end
if RS:FindFirstChild("Pets_Folder"):WaitForChild(temp.Name).Difficulty.Value ~= "Exclusive" then
Difficulty.ExclusiveGradient.Enabled = false
Difficulty.BackgroundTransparency = 1
end
local NoteTemplate = RS:FindFirstChild("Pets_Folder"):WaitForChild(temp.Name)
if NoteTemplate:FindFirstChild("Note") then
InfoFrame.Note.Visible = true
InfoFrame.Note.Text = RS:FindFirstChild("Pets_Folder"):WaitForChild(temp.Name).Note.Value
else
InfoFrame.Note.Visible = false
InfoFrame.Note.Text = "NaN"
end
end
for i, v in pairs(Pets:GetChildren()) do
local newTemplate = template:Clone()
newTemplate.Name = v.Name
newTemplate.Parent = scrollingFrame
newTemplate.Visible = true
newTemplate.PetImage.Image = v:WaitForChild("Image").Texture
local Handler = RS:FindFirstChild("Pets_Folder"):FindFirstChild(newTemplate.Name)
if Handler.Difficulty.Value == "Easy" then
newTemplate.LayoutOrder = -7
else
if Handler.Difficulty.Value == "Medium" then
newTemplate.LayoutOrder = -6
else
if Handler.Difficulty.Value == "Hard" then
newTemplate.LayoutOrder = -5
else
if Handler.Difficulty.Value == "Insane" then
newTemplate.LayoutOrder = -4
else
if Handler.Difficulty.Value == "Extreme" then
newTemplate.LayoutOrder = -3
else
if Handler.Difficulty.Value == "Exclusive" then
newTemplate.LayoutOrder = -2
else
if Handler.Difficulty.Value == "Event" then
newTemplate.LayoutOrder = -1
end
end
end
end
end
end
end
newTemplate.MouseButton1Click:Connect(function()
selectTemplate(newTemplate)
Click:Play()
scrollingFrame.Visible = false
end)
end
The script used for the remote to get the number of how much a pet exists: - Server Script
local save = dss:GetDataStore("ExistsValue")
local rs2 = game:WaitForChild("ReplicatedStorage")
rs2:WaitForChild("GetPetExistsValue").OnServerInvoke = function(player, temp)
if rs2:FindFirstChild("Pets_Folder"):WaitForChild(temp) then
local ExistsValue = rs2["Pets_Folder"]:FindFirstChild(temp)
local num = save:GetAsync("ExistsValue", ExistsValue)
return num
end
end
In here to prevent replicas from showing, you can use this (using this code means add a TextLabel of some sort named Duplicates):
local alreadyHave = {}
for i, v in pairs(Pets:GetChildren()) do
local duplicates = 0
if not table.find(alreadyHave, v) then
local newTemplate = template:Clone()
newTemplate.Name = v.Name
newTemplate.Parent = scrollingFrame
newTemplate.Visible = true
table.insert(alreadyHave, v)
for _, pet in pairs(Pets:GetChildren()) do
if pet == v then duplicates += 1 end
end
else continue end
--code inbetween
newTemplate.Duplicates.Text = duplicates
end
local alreadyHave = {}
for i, v in pairs(Pets:GetChildren()) do
local duplicates = 0
if not table.find(alreadyHave, v) then
local newTemplate = template:Clone()
newTemplate.Name = v.Name
newTemplate.Parent = scrollingFrame
newTemplate.Visible = true
table.insert(alreadyHave, v)
for _, pet in pairs(Pets:GetChildren()) do
if pet == v then duplicates += 1 end
end
else continue end
--code inbetween
newTemplate.Duplicates.Text = duplicates
end
Edit: I proofread it and it should work when inserted. I hope it helps!
Sorry, again. I forgot about that, here’s your fix:
local alreadyHave = {}
for i, v in pairs(Pets:GetChildren()) do
local duplicates = 0
local newTemplate
if not table.find(alreadyHave, v) then
newTemplate = template:Clone()
newTemplate.Name = v.Name
newTemplate.Parent = scrollingFrame
newTemplate.Visible = true
table.insert(alreadyHave, v)
for _, pet in pairs(Pets:GetChildren()) do
if pet == v then duplicates += 1 end
end
else continue end
--code inbetween
newTemplate.Duplicates.Text = duplicates
end
This is the kinda trial-and-error stuff my brain does when coding. (lol)