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)
Still no luck huh? Been looking around for a solution to this as well, and the only thing I can think of that could handle the traffic is an offsite database
create your own api, update your values this way, dont update your database everytime a new item is found/unboxed since that will hit database rate limits quickly, instead, cache the amoutn of new found items, and deploy the new unboxed items changes every 10-20 seconds to your database
Hate to say it, but you’re a little late! I did end up pretty much doing exactly that tho lol.
PostgreSQL database offsite hooked up to NodeJS & Express. Game pings every 5 min or so (or when it shuts down) about what items have been spawned (or deleted) and updates accordingly. Pretty cool stuff! Lots of “trade warriors” in my game use this feature to the nth degree when figuring out a value for an item.
For anyone who finds themselves looking to create a system like this, @baukeblox12’s way and/or my way is probably your best bet. Good luck to all!