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
- Sample Photos
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)