How to this Pet Shop? Help

Please help me, I’m confused about where else to look for help.

I am making a Pet Shop, but I have a problem In equip pet, where if I equip a pet. the pet will clone so many if I click equip

I have searched for this problem. on Youtube and also my discord friends but they all don’t know how.

[Video Pet]

and i don’t know if this script is wrong

Code script [1]

local function equip(player,SPets)
	local char = player.Character or player.CharacterAdded:Wait()
	local head = char.HumanoidRootPart
	local Pet = game.ReplicatedStorage.SPet[SPets].ModelPet.Inner:Clone()
	Pet.Name = "Pet"
	Pet.Parent = player.Character
	player.PetEquipped.Value = SPets

	local bodyPos = Instance.new("BodyPosition", Pet)
	bodyPos.MaxForce = Vector3.new(math.huge,math.huge,math.huge)

	local bodygyro = Instance.new("BodyGyro", Pet)
	bodygyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	while wait() do
		bodyPos.Position = head.Position + Vector3.new(2,2,5)
		bodygyro.CFrame = head.CFrame
	end
end



script.Parent.BuyEvent.OnServerEvent:Connect(function(player,SPets)
	local ShPets = game.ReplicatedStorage.SPet[SPets]
	local Price = ShPets.Price
	local humrootpart = player.Character. HumanoidRootPart
	if Price.Value >= Price.Value and not ShPets.Price:FindFirstChild("ID") then
		Price.Value = Price.Value - Price.Value
		player.LePet[SPets].Value = true
	elseif player.LePet:FindFirstChild(SPets) and player.LePet[SPets].Value == true then
		equip(player,SPets)
		if player.Character:FindFirstChild("MeshPart") then
			player.Character.Pet:Destroy()
		end
	end
end)

Code script [2]

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		wait(1)
		local PetS = player.PetEquipped
		local humrootpart = player.Character. HumanoidRootPart
		if PetS and PetS.Value ~= "" and player.Character and player.Character:FindFirstChild("HumanoidRootPart") and player.LePet[PetS.Value].Value == true then
			local Pet = game.ReplicatedStorage.Trails[PetS.Value].ModelPet.Inner:Clone()
			Pet.Name = "Pet"
			Pet.Parent = player.Character


			local bodyPos = Instance.new("BodyPosition", Pet)
			bodyPos.MaxForce = Vector3.new(math.huge,math.huge,math.huge)

			local bodygyro = Instance.new("BodyGyro", Pet)
			bodygyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
			while wait() do
				bodyPos.Position = humrootpart.Position + Vector3.new(2,2,5)
				bodygyro.CFrame = humrootpart.CFrame
			end
			
		end
		if PetS and PetS.Value ~= "" and player.LePet[PetS.Value].Value == false then
			player.PetEquipped.Value = ""
		end
	end)
end)

Code script [3]

local Save = game:GetService("DataStoreService"):GetDataStore("SalvamentoDeLePet_")
local SaveEquip = game:GetService("DataStoreService"):GetDataStore("SalvamentoPetEquipada_")
game.Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder",player)
	Folder.Name = "LePet"
	
		local userdata
		pcall (function()
			userdata = Save:GetAsync(player.userId)
		end)

	if userdata then
		for key, value in pairs(userdata) do
		local Pets = Instance.new("BoolValue",Folder)
			Pets.Name = key
			Pets.Value = value
		end
		
		for i,v in pairs(game.ReplicatedStorage.SPet:GetChildren()) do
			if v:IsA("Folder") and not player.LePet:FindFirstChild(v.Name) then
				local Pets = Instance.new("BoolValue",Folder)
				Pets.Name = v.Name
				Pets.Value = false	
		end
		end
		
	else
		for i,v in pairs(game.ReplicatedStorage.SPet:GetChildren()) do
		if v:IsA("Folder") then
				local Pets = Instance.new("BoolValue",Folder)
				Pets.Name = v.Name 
				Pets.Value = false
		end
		end
	end
	
	local Equip = Instance.new("StringValue",player)
	Equip.Name = "PetEquipped"
	Equip.Value = SaveEquip:GetAsync(player.UserId) or ""
end)

game.Players.PlayerRemoving:Connect(function(player)
	local trails = {
	}
	for _,v in pairs (player.LePet:GetChildren()) do
		if game.ReplicatedStorage.SPet[v.Name].Price:FindFirstChild("ID") or game.ReplicatedStorage.SPet[v.Name].Price:FindFirstChild("Group") then
		else
			trails[v.Name] = v.Value
	end
		end
	Save:SetAsync(player.UserId,trails)		
	SaveEquip:SetAsync(player.UserId,player.PetEquipped.Value)
end)
1 Like

I need to know where is the script that calls the remote event (BuyEvent)

For example: “BuyEvent:FireServer(…)”

2 Likes

You want it to like be only 1 pet at a time like (1/1) or you want it to be multiple like (1/3)…?

1 Like

I only need 1 pet equipment
.
Sorry I’m late in replying to your comment because I forgot to open this forum.

1 Like

here

local function equip(player,SPets)
	local char = player.Character or player.CharacterAdded:Wait()
	local head = char.HumanoidRootPart
	local Pet = game.ReplicatedStorage.SPet[SPets].ModelPet.Inner:Clone()
	Pet.Name = "Pet"
	Pet.Parent = player.Character
	player.PetEquipped.Value = SPets

	local bodyPos = Instance.new("BodyPosition", Pet)
	bodyPos.MaxForce = Vector3.new(math.huge,math.huge,math.huge)

	local bodygyro = Instance.new("BodyGyro", Pet)
	bodygyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	while wait() do
		bodyPos.Position = head.Position + Vector3.new(2,2,5)
		bodygyro.CFrame = head.CFrame
	end
end



script.Parent.BuyEvent.OnServerEvent:Connect(function(player,SPets)
	local ShPets = game.ReplicatedStorage.SPet[SPets]
	local Price = ShPets.Price
	local humrootpart = player.Character. HumanoidRootPart
	if Price.Value >= Price.Value and not ShPets.Price:FindFirstChild("ID") then
		Price.Value = Price.Value - Price.Value
		player.LePet[SPets].Value = true
	elseif player.LePet:FindFirstChild(SPets) and player.LePet[SPets].Value == true then
		equip(player,SPets)
		if player.Character:FindFirstChild("MeshPart") then
			player.Character.Pet:Destroy()
		end
	end
end)```

That´s not the script, I finding the script that fires the event to the remote, I think that´s problem, such as a loop that fires the event.

1 Like

I don’t know. But you can change it in this studio file
maybe you can find the error here
Pet.rbxl (89.5 KB)

Oh, I read the post again, and now I understand,

Well, I have a solution for your pet system, Im going to use ObjectsValues.

Can I change your scripts?

Result.rbxl (89.7 KB)

I added 2 things,

A bool value that indicates if the pet is eqquiped and
an object Value for get the pet objetct.

1 Like

thank you very much bro :laughing:

1 Like

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