Hello. Ive made a pet system, everything works well until the player dies. All of the pets the player had in their inventory disappear from their inventory with no errors. Does anybody know how I can fix this?
local function addToFrame(pet) local newTemplate = Template:Clone() newTemplate.Name = pet.Name newTemplate.PetName.Text = pet.Name newTemplate.Parent = scrollframe local NewPet = pet:Clone() NewPet.Parent = newTemplate.PetImage local camera = Instance.new("Camera") camera.CFrame = CFrame.new(NewPet.PrimaryPart.Position + (NewPet.PrimaryPart.CFrame.LookVector * 3),NewPet.PrimaryPart.Position) camera.Parent = newTemplate.PetImage newTemplate.PetImage.CurrentCamera = camera buttonconnections[#buttonconnections + 1] = newTemplate.MouseButton1Click:Connect(function() if newTemplate.Equipped.Text == "EQUIPPED" then -- they want to unequip it game.ReplicatedStorage.UnEquipPet:FireServer() newTemplate.Equipped.Text = "UNEQUIPPED" newTemplate.Equipped.TextColor3 = Color3.fromRGB(255,0,0) else game.ReplicatedStorage.EquipPet:FireServer(pet.Name) SetTemplateEquipped(newTemplate) end end) end game.ReplicatedStorage.SendData.OnClientEvent:Connect(function(PetNames) for i,petName in pairs(PetNames)do if game.ReplicatedStorage.Egg1:FindFirstChild(petName) then addToFrame(game.ReplicatedStorage.Egg1:FindFirstChild(petName)) end end end) game.ReplicatedStorage.SetEquippedPet.OnClientEvent:Connect(function(PetName) if scrollframe:FindFirstChild(PetName)then SetTemplateEquipped(scrollframe[PetName]) end end)
go the the screengui and set "ResetOnSpawn" to false
Try to store the pets in a player folder created by a script (Example game.Players.LocalPlayer.PetStorage.PET) and if the player leaves the game, you will need to use datastores