Hello,

if anyone could give me some advice that would be awesome! I have been stuck dealing with this issue for a couple of weeks.

I want a pet in my inventory to appear when clicking Equip, as well as disappear when Unequipped.

I have the code already laid out, though the pet still won't appear!

Here is the code, a regular Script in ServerScriptService

game.Players.PlayerAdded:Connect(function(player)
	
	local equippedPet = Instance.new("StringValue")
	equippedPet.Name = "EquippedPet"
	equippedPet.Parent = player
	
	local inventory = Instance.new("Folder")
	inventory.Name = "PetInventory"
	inventory.Parent = player
	
	
	player.CharacterAdded:Connect(function(char)
		if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
			equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
			
			end
		end)
	
	 equippedPet.Changed:Connect(function()
		if equippedPet.Value ~= nil then
			if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
			equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
			
			end
		end
		
		
		
	end)
	
end)

game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
	local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
	
	if pet and player.PetInventory:FindFirstChild(petName) then
		player.EquippedPet.Value = petName
		
		
		
	end
	
	
end)

game.ReplicatedStorage.UnequipPet.OnServerEvent:Connect(function(player)
	     player.EquippedPet.Value = ""
	if player.Character:FindFirstChild(player.Name.."'s Pet") then
		player.Character[player.Name.."'s Pet"]:Destroy()
	end
	if player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
		player.Character.HumanoidRootPart:FindFirstChlid("attachmentCharacter"):Destroy()
		
		
	end
	
	
	
end)

I tried moving the script out of ServerScriptService but that was no help. I also tried adding a RemoteEvent but didn’t code it correctly due to that not working either.

2 comments

0

Show us where the error/problem is. Nobody's gonna read all of that

0

I don't have any errors but if it helps, the script at line 34 won't update my string value for server side or add the pet to the players inventory