How to make this?

hello can someone help me with this? so i made a Pet Shop. where if i buy then the Pet. will move from inventory but the pet clones a lot from inventory?

Pet Shop

I want to make my Pet Shop like this, but what if people buy the same pet. then it will not clone to inventory

My script

local replicatedStorage = game:GetService("ReplicatedStorage")
local runService = game:GetService("RunService") 
local tweenService = game:GetService("TweenService")
local uis = game:GetService("UserInputService")

local player = game.Players.LocalPlayer

local Module3D = require(replicatedStorage:WaitForChild("Module3D"))

local frame = script.Parent
local info = frame.Info
local displayPet = info.DisplayPet
local container = frame.Container
local template = container.Template
local petNameDisplayInfo = info.PetName
local equipBTN = info.Equip
local delete = info.Delete

local selectedTemplate = nil

local function onEquip()
	if selectedTemplate ~= nil then
		if selectedTemplate:FindFirstChild("Equipped").Value == false then
			local result = replicatedStorage.EggHatchingRemotes.EquipPet:InvokeServer(selectedTemplate.Name)

			if result == "Equip" then
				selectedTemplate.Checkmark.Visible = true
				equipBTN.Text = "Unequip"
				selectedTemplate:FindFirstChild("Equipped").Value = true
			elseif result == "Unequip" then
				equipBTN.Text = "Equip"
				selectedTemplate.Checkmark.Visible = false

				selectedTemplate:FindFirstChild("Equipped").Value = false
			end
		else
			local result = replicatedStorage.EggHatchingRemotes.UnequipPet:InvokeServer(selectedTemplate.Name)

			if result == true then
				equipBTN.Text = "Equip"
				selectedTemplate.Checkmark.Visible = false


				selectedTemplate:FindFirstChild("Equipped").Value = false
			end
		end

	end
end

local function onTemplatePress(temp)
	selectedTemplate = temp
	if selectedTemplate:FindFirstChild("Equipped").Value == true then
		equipBTN.Text = "Unequip"
		selectedTemplate.Checkmark.Visible = true

	else
		selectedTemplate.Checkmark.Visible = false

		equipBTN.Text = "Equip"
	end
	petNameDisplayInfo.Text = temp.Name
	
	
	for i, v in pairs(displayPet:GetChildren()) do 
		if v:IsA("ViewportFrame") then
			v:Destroy()
		end
	end
	
	info.Multiplier1.Text = "x"..replicatedStorage.Pets:FindFirstChild(temp.Name, true).Multiplier1.Value.." Coins"
	
	local petModel = Module3D:Attach3D(displayPet,replicatedStorage.Pets:FindFirstChild(temp.Name, true):Clone())
	petModel:SetDepthMultiplier(1.2)
	petModel.Camera.FieldOfView = 5
	petModel.Visible = true

	runService.RenderStepped:Connect(function()
		petModel:SetCFrame(CFrame.Angles(0,tick() * 2 % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
	end)
end

local function deletePet()
	if selectedTemplate ~= nil then
		replicatedStorage.EggHatchingRemotes.DeletePet:FireServer(selectedTemplate.Name)
		
		selectedTemplate:Destroy()
		selectedTemplate = nil
		
		petNameDisplayInfo.Text = "Nothing"


		for i, v in pairs(displayPet:GetChildren()) do 
			if v:IsA("ViewportFrame") then
				v:Destroy()
			end
		end

		info.Multiplier1.Text = "x0"
		
		equipBTN.Text = "EQUIP"
	end
end

_G.newTemplate = function(petName)
	local newTemplate = template:Clone()
	newTemplate.Name = petName
	newTemplate.Visible = true
	newTemplate.NamaPetNya.Text = petName
	newTemplate.FotoInPet.Image = replicatedStorage.Pets:FindFirstChild(petName, true).FotoPet.Value

	newTemplate.Parent = container

	newTemplate.MouseButton1Click:Connect(function()
		onTemplatePress(newTemplate)
	end)
end

equipBTN.MouseButton1Click:Connect(function()
	onEquip()
end)


delete.MouseButton1Click:Connect(function()
	deletePet()
end)

wait(2)

for i, v in pairs(player.Pets:GetChildren()) do 
	_G.newTemplate(v.Name)
end

but if this is not a script you can open my File Studio
ShopPet_dduck5tar.rbxl (160.9 KB)

1 Like

the idea here is you create bunny if it doesnt already exist as a child in the list, if it does then you simply keep track of how many exists, update the text for numofpet.

1 Like

So where should I start creating the script?

You could add a Number Value inside of the GUI Child (the button) and keep track of how many there are there. Then when the value is changed, you can post the new number onto the TextLabel which shows the item amount.

1 Like

so i should start from here???

Yep and inside the newTemplate function you could add a check if this pet already exists, if it does, then increase the number value by 1.

1 Like

is this the code? if wrong please give me an example of the script code???

local function Pet(TextButton)
	if not TextButton:IsA("TextButton") then return end
	if script.Parent:FindFirstChild(TextButton.Name) then return end
	_G.newTemplate(v.Name)
end

template.ChildAdded:Connect(Pet)
for I, X in template:GetChildren() do Pet(X) end

Here’s an example of what I mean:

function newTemplate(name)
     local exists = scrollgui:FindFirstChild(name)
     if exists then
          exists.amount.Value += 1
     end
end

Add this to the code within G_.newTemplate. This will automatically add the number to the Button you are creating to represent the pet.

uhh i am confused about this can you fix it in this Roblox Studio File
ShopPet_dduck5tar.rbxl (160.9 KB)

Here you are, it should now count up how many you have. However I did not add functionality for pet removal.
image
ShopPet_dduck5tar.rbxl (161.4 KB)

1 Like

Thank you very much thank you thank you :smiley: :star_struck:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.