Need help with this error!

I got this error in my code.

ServerScriptService.MainInventoryScript:77: Expected ‘end’ (to close ‘function’ at line 1), got ; did you forget to close ‘then’ at line 69?

I dont know what I did wrong but I need help. Here’s my code,

local function equipPet(player, pet)
	
	local character = player.Character
	
	if pet ~= nil and character ~= nil then
		
		if character:FindFirstChild(player.Name.."'s Pet") then 
			character[player.Name.."'s Pet"]:Destroy() 
		end
		
		if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
			if character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy() then
		end
			
		pet.Name = player.Name.."'s Pet"
		
		pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
		
		local modelSize = pet.PrimaryPart.Size
		
		local attachmentCharacter = Instance.new ("Attachment")
		attachmentCharacter.Visible = false
		attachmentCharacter.Name = "attachmentCharacter"
		attachmentCharacter.Parent = character.HumanoidRootPart
		attachmentCharacter.Position = Vector3.new(1,1,0) + modelSize
		
		local attachmentPet = Instance.new("Attachment")
		attachmentPet.Visible = false
		attachmentPet.Parent = pet.PrimaryPart
		
		local alignPosition = Instance.new("AlignPosition")
		alignPosition.MaxForce = 25000
		alignPosition.Attachment0 = attachmentPet
		alignPosition.Attachment1 = attachmentCharacter
		alignPosition.Responsiveness = 25
		alignPosition.Parent = pet
		
		local alignOrientation = Instance.new("AlignOrientation")
		alignOrientation.MaxTorque = 25000
		alignOrientation.Attachment0 = attachmentPet
		alignOrientation.Attachment1 = attachmentCharacter
		alignOrientation.Responsiveness = 25
		alignOrientation.Parent = pet
		
		pet.Parent = character
		
	end
	
end

game.Players.PlayerAdded:Connect(function(player)
	
	local inventory = Instance.new("Folder")
	inventory.Name = "PetInventory"
	inventory.Parent = player
	
	local equippedPet = Instance.new("StringValue")
	equippedPet.Name = "EquippedPet"
	equippedPet.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)

Help Pls!

1 Like

You just missed one end statement, usually this is what’s known as a “syntax error”

local function equipPet(player, pet)

	local character = player.Character

	if pet ~= nil and character ~= nil then

		if character:FindFirstChild(player.Name.."'s Pet") then 
			character[player.Name.."'s Pet"]:Destroy() 
		end

		if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
			if character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy() then
			end

			pet.Name = player.Name.."'s Pet"

			pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)

			local modelSize = pet.PrimaryPart.Size

			local attachmentCharacter = Instance.new ("Attachment")
			attachmentCharacter.Visible = false
			attachmentCharacter.Name = "attachmentCharacter"
			attachmentCharacter.Parent = character.HumanoidRootPart
			attachmentCharacter.Position = Vector3.new(1,1,0) + modelSize

			local attachmentPet = Instance.new("Attachment")
			attachmentPet.Visible = false
			attachmentPet.Parent = pet.PrimaryPart

			local alignPosition = Instance.new("AlignPosition")
			alignPosition.MaxForce = 25000
			alignPosition.Attachment0 = attachmentPet
			alignPosition.Attachment1 = attachmentCharacter
			alignPosition.Responsiveness = 25
			alignPosition.Parent = pet

			local alignOrientation = Instance.new("AlignOrientation")
			alignOrientation.MaxTorque = 25000
			alignOrientation.Attachment0 = attachmentPet
			alignOrientation.Attachment1 = attachmentCharacter
			alignOrientation.Responsiveness = 25
			alignOrientation.Parent = pet

			pet.Parent = character

		end

	end

	game.Players.PlayerAdded:Connect(function(player)

		local inventory = Instance.new("Folder")
		inventory.Name = "PetInventory"
		inventory.Parent = player

		local equippedPet = Instance.new("StringValue")
		equippedPet.Name = "EquippedPet"
		equippedPet.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)
end

You forgot an end to close off your function

local function equipPet(player, pet)

	local character = player.Character

	if pet ~= nil and character ~= nil then

		if character:FindFirstChild(player.Name.."'s Pet") then 
			character[player.Name.."'s Pet"]:Destroy() 
		end

		if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
			if character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy() then
			end

			pet.Name = player.Name.."'s Pet"

			pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)

			local modelSize = pet.PrimaryPart.Size

			local attachmentCharacter = Instance.new ("Attachment")
			attachmentCharacter.Visible = false
			attachmentCharacter.Name = "attachmentCharacter"
			attachmentCharacter.Parent = character.HumanoidRootPart
			attachmentCharacter.Position = Vector3.new(1,1,0) + modelSize

			local attachmentPet = Instance.new("Attachment")
			attachmentPet.Visible = false
			attachmentPet.Parent = pet.PrimaryPart

			local alignPosition = Instance.new("AlignPosition")
			alignPosition.MaxForce = 25000
			alignPosition.Attachment0 = attachmentPet
			alignPosition.Attachment1 = attachmentCharacter
			alignPosition.Responsiveness = 25
			alignPosition.Parent = pet

			local alignOrientation = Instance.new("AlignOrientation")
			alignOrientation.MaxTorque = 25000
			alignOrientation.Attachment0 = attachmentPet
			alignOrientation.Attachment1 = attachmentCharacter
			alignOrientation.Responsiveness = 25
			alignOrientation.Parent = pet

			pet.Parent = character

		end
	end
end

game.Players.PlayerAdded:Connect(function(player)

	local inventory = Instance.new("Folder")
	inventory.Name = "PetInventory"
	inventory.Parent = player

	local equippedPet = Instance.new("StringValue")
	equippedPet.Name = "EquippedPet"
	equippedPet.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)