Re-assigning pet to player on reset

repo.rbxl (41.1 KB)
I’m trying to re-assign a pet to the player once the player resets, because the pet doesn’t know where to go afterwards. I’ve tried destroying the pet, my initial solution was to destroy the pet and re-clone it into the player but that essentially leaves the variables in the local script that controls the pet hanging, and it often causes bugs like the player freezing and whatnot. I’ve provided a repo of my pet system, which isn’t the final product but will provide an example of how I am handling the pet’s movements.

Do you mean the character? If so you could always use a system like this:

Where you could use a function which returns the character so that you always have the correct character, even if it resets.

Otherwise you could use a CharacterAdded function which updates the pet position/instance every time the character is added. I think that would be the easiest way to be honest.

1 Like

Hey!
Change the position of the petController to StarterCharacterScripts.
Then create a new script in the same folder with the following code:

local player = game.Players.LocalPlayer
local trackerInventory = player:WaitForChild("Backpack").InventoryTracker

for i, v in pairs(game.Workspace:GetChildren()) do
	if v.Name == "Bunny" then
		local findItem = trackerInventory:FindFirstChild(v.Name)
		if findItem then
			findItem.Value = findItem.Value + 1
		elseif not findItem then
			local newTracker = Instance.new("IntValue")
			newTracker.Parent = trackerInventory
			newTracker.Name = v.Name
			newTracker.Value = newTracker.Value + 1
		end
		game.ReplicatedStorage.controlPet:Fire(v)
	end
end

Now it should work fine again.

1 Like