Hello, everybody as you could see in the title i am working on an inventory but the player can just spam the Equip button and get infinite cats how do I make it so the cat only clones one time.
Here is a video.
As you just saw in the brief video the cat clone several times, but I don’t that to happen. The clone() built-in function ran several unnecessary times. Here is the code.
Local Script
local Equip = script.Parent
local InvHandler = game.Players.LocalPlayer.PlayerGui.InventoryHandler
local UpperInv = InvHandler.UpperInv
local MaxPetLimit = UpperInv.MaxPetLimit
local PetLimitText = MaxPetLimit.PetLimitText
local PetPreview = UpperInv.PetPreview
local PetPreviewFrame = PetPreview.PetPreviewFrame
local Im = PetPreviewFrame.PetPreviewImage
local TotalPets = PetLimitText.TotalPets
local invScroll = InvHandler.InventoryScrollBar
local checkC1 = invScroll.check1:Clone()
-- We just defined all the UI elements
local ReplicatedStorage = game:GetService("ReplicatedStorage")
Equip.MouseButton1Click:Connect(function()
if Im.Image =="rbxassetid://7620353586" then -- if its the cat then show a picture of it
checkC1.Visible = true
checkC1.Parent = invScroll:WaitForChild("PetForInvImCat")
checkC1.Size = UDim2.new(0,75,0,75)
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet") -- Remote event
while EquipPet == nil do wait() end
TotalPets.Value = TotalPets.Value + 1 -- Keeping track of how much pets are Equipped
PetLimitText.Text = TotalPets.Value.."/5"
if TotalPets.Value > 5 then
PetLimitText.Text = "5/5"
TotalPets.Value = 5
end
local CatStatus = Instance.new("StringValue")
CatStatus.Name = "CatStatus"
CatStatus.Value = "Equipped" -- Status of the pet tells if the pet is Equipped or not(really not that helpful)
CatStatus.Parent = PetLimitText
EquipPet:FireServer()-- Equip pet is the Remote event
print("The Event Fired ")
end
end)
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BasicEggPetFolder = ReplicatedStorage.BasicEggPetFolder
local Cat = BasicEggPetFolder.Cat
local Dog = BasicEggPetFolder.Dog
local Mouse = BasicEggPetFolder.Mouse
local Dragon = BasicEggPetFolder.Dragon
local GrassyCat = BasicEggPetFolder.GrassyCat
local TeaMonster = BasicEggPetFolder.TeaMonster
EquipPet.OnServerEvent:Connect(function(player)
local char = player.Character
local humRoot = char:FindFirstChild("HumanoidRootPart")
local Cat = BasicEggPetFolder.Cat
local Clo1 = Cat:Clone() -- when the player remote events runs we clone the cat in the player's char
Clo1.Parent = char
while true do
wait()
Clo1:SetPrimaryPartCFrame(humRoot.CFrame * CFrame.new(2,2,2)) -- Postioning the pet
end
print(Clo1)
end)
I am just asking for the cat not to clone multiple times