Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Pets disappear from players inventory when player dies?

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)

2 answers

✓ Accepted answer

go the the screengui and set "ResetOnSpawn" to false

1 comment

0

Thank you so much! I've been struggling with this problem for ages, and I just realised I could do that.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.